springboot集成dubbo

摘要  springboot国外用的比较多,而dubbo国外又很少用,所有集成例子比较少。

  1. dubbo XML文件引用:@ImportResource("classpath:dubbo-consum.xml")

  2. 有的springboot版本会出现,dubbo注册服务的xml文件中引用的service报错不能注入,需要加入<dubbo:annotation package="com.dubbo.*" />

  3. dubbo XSD文件需要手动导入到开发工具中

  4. 最头疼的一个,就是版本冲突,首先是dubbo与spring的冲突,然后是zk与sf4j的冲突。


  5. ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    <dependency>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-starter-web</artifactId>
                 <version>${spring.boot.version}</version>
             </dependency>
             
             <dependency>
                 <groupId>com.alibaba</groupId>
                 <artifactId>dubbo</artifactId>
                 <version> 2.5 . 3 </version>
                 <exclusions>
                     <exclusion>
                         <groupId>org.springframework</groupId>
                         <artifactId>spring</artifactId>
                     </exclusion>
                 </exclusions>
             </dependency>
             <dependency>
                 <groupId>org.apache.zookeeper</groupId>
                 <artifactId>zookeeper</artifactId>
                 <version> 3.4 . 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>
  6. ?
    1
    上面的maven引入springboot用的版本是 1.3 . 0
  7. ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <?xml version= "1.0"  encoding= "UTF-8" ?>
    <beans xmlns= "http://www.springframework.org/schema/beans"
        xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:jee= "http://www.springframework.org/schema/jee"
         xmlns:tx= "http://www.springframework.org/schema/tx"
         xmlns:dubbo= "http://code.alibabatech.com/schema/dubbo"
         xmlns:context= "http://www.springframework.org/schema/context"
         xsi:schemaLocation="http: //www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
         http: //www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
         http: //www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
         http: //code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
         http: //www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"
         default -lazy-init= "false"  >
        <!-- 提供方应用名称信息,这个相当于起一个名字,我们dubbo管理页面比较清晰是哪个应用暴露出来的 -->
        <dubbo:application name= "dubbo-provider-dsp" ></dubbo:application>
        <dubbo:annotation  package = "pring.boot.*"  />
        <!-- 使用zookeeper注册中心暴露服务地址 -->  
        <dubbo:registry address= "zookeeper://192.168.2.164:2181"  check= "false"  subscribe= "false"  register= "" ></dubbo:registry>
       <!-- 要暴露的服务接口 -->  
       <dubbo:service  interface = "pring.boot.service.dubbo.DubboService"  ref= "dubboService"  />  
    </beans>
  8. ?
    1
    上面是生产者dubbo xml文件,文件放在resources中
  9. ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    @SpringBootApplication
    @ImportResource ( "classpath:dubbo-consum.xml" )
    public  class  Application {
     
         public  static  void  main(String[] args)  throws  Exception {
             SpringApplication.run(Application. class , args);
         }
     
    }
  10. ?
    1
    这是引用dubbo文件,生产者和消费者都是一样引入。
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version= "1.0"  encoding= "UTF-8" ?>  
<beans xmlns= "http://www.springframework.org/schema/beans"  
     xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"  
     xmlns:dubbo= "http://code.alibabatech.com/schema/dubbo"  
     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:application name= "dubbo-custom-dsp" />   
     <dubbo:registry address= "zookeeper://192.168.2.164:2181"  />  
     <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->  
     <dubbo:reference id= "dubboService"  interface = "pring.boot.service.dubbo.DubboService"  />  
</beans>
这是消费者dubbo xml文件 文件位置跟生产者一样
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值