spring boot (三) 集成dubbo

springboot集成dubbo 需要导入dubbo所需jar的依赖

  
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>dubboartifactId>
            <version>2.5.3version>
            <exclusions>
                <exclusion>
                    <artifactId>springartifactId>
                    <groupId>org.springframeworkgroupId>
                exclusion>
            exclusions>
        dependency>


       
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>fastjsonartifactId>
            <version>1.2.21version>
        dependency>
        <dependency>
            <groupId>org.apache.zookeepergroupId>
            <artifactId>zookeeperartifactId>
            <version>3.3.6version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4jgroupId>
                    <artifactId>slf4j-log4j12artifactId>
                exclusion>
                <exclusion>
                    <groupId>log4jgroupId>
                    <artifactId>log4jartifactId>
                exclusion>
            exclusions>
        dependency>

        <dependency>
            <groupId>com.github.sgroschupfgroupId>
            <artifactId>zkclientartifactId>
            <version>0.1version>
        dependency>

dubbo启动时默认会加载classpath下dubbo.properties的配置文件

因为也采用配置文件的方式加载参数

dubbo.application.name=springboot-sample
dubbo.application.owner=zhs
dubbo.application.logger=slf4j
dubbo.registry.address=zookeeper://zookeeper.com:2181
dubbo.monitor.protocol=registry
dubbo.protocol.name=dubbo
dubbo.protocol.port=20887
dubbo.service.loadbalance=roundrobin
dubbo.registry.file=dubboRegistry/registry.file

同时需要导入外部的spring的配置文件来配置dubbo发布服务的配置和调用的配置 spring-dubbo.xml

需要启动的zookeepper注册中心正常流程启动



<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://code.alibabatech.com/schema/dubbo
       http://code.alibabatech.com/schema/dubbo/dubbo.xsd">


    
    
    
    
    
    


    <dubbo:reference interface="com.order.server.UserServer" id="userServer" check="false"/>
    <dubbo:reference interface="com.order.server.AuthServer" id="authServer"/>
    <dubbo:reference interface="com.order.server.UserMoneyServer" id="userMoneyServer"/>
    <dubbo:reference interface="com.order.server.UserIntegrateServer" id="userIntegrateServer"/>
    <dubbo:reference interface="com.order.server.TaskServer" id="taskServer"/>

beans>

入口主类添加注解:@ImportResource({“spring-dubbo.xml”})

@SpringBootApplication
@MapperScan("com.sample.dao")
@ImportResource({"spring-dubbo.xml"})
public class SampleMybatisApplication{

        private static Logger logger = Logger.getLogger(SampleMybatisApplication.class);

        /**
         * Main Start
         */
        public static void main(String[] args) {
            SpringApplication.run(SampleMybatisApplication.class, args);
            logger.info("============= SpringBoot Start Success =============");
        }

    }

dubbo集成完成

你可能感兴趣的:(spring,boot)