spring boot (三) 集成dubbo

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

  <!-- dubbo dependency -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.5.3</version>
            <exclusions>
                <exclusion>
                    <artifactId>spring</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
            </exclusions>
        </dependency>


       <!--fastJson-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.21</version>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <version>3.3.6</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.github.sgroschupf</groupId>
            <artifactId>zkclient</artifactId>
            <version>0.1</version>
        </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注册中心正常流程启动

<?xml version="1.0" encoding="UTF-8"?>
<!--suppress SpringFacetInspection -->
<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">


    <!--&lt;!&ndash; 提供方应用信息,用于计算依赖关系 &ndash;&gt;-->
    <!--<dubbo:application name="yy-web-backend-app"/>-->
    <!--&lt;!&ndash; 使用multicast广播注册中心暴露服务地址 &ndash;&gt;-->
    <!--<dubbo:registry address="zookeeper://zookeeper.com:2181" file="./registry.file"/>-->
    <!--&lt;!&ndash; 用dubbo协议在20880端口暴露服务 &ndash;&gt;-->
    <!--<dubbo:protocol name="dubbo"  port="30908"/>-->


    <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集成完成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值