spring boot集成dubbo

作者: 异类_8b7a | 来源:发表于2019-07-05 14:07 被阅读5次

    github地址
    添加下面的依赖:

    <dependency>
          <groupId>com.alibaba.spring.boot</groupId>
          <artifactId>dubbo-spring-boot-starter</artifactId>
          <version>2.0.0</version>
    </dependency>
    

    添加配置文件:具体的属性可以在DubboProperties.java类中查看。下面是配置消费者方式:

    spring:
      dubbo:
        application:
          name: market-research
        server: false
        registry:
          address: zookeeper://1.1.1.1:2181?backup=1.1.1.2:2181,1.1.1.3:2181
        monitor:
          protocol: registry
    

    在App.java上添加@EnableDubboConfiguration注解,完成自动装配:

    @SpringBootApplication
    @EnableDubboConfiguration
    public class App {
        public static void main(String[] args) {
            SpringApplication.run(App.class, args);
        }
    }
    

    使用@Reference注解注入需要消费的服务:

    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class Consumer{
        @Reference(timeout = 3000)
        private SaleApiService saleApiService;
    
        @Test
        public void testQuery(){
            saleApiService.query(xxx);
        }
    }
    

    相关文章

      网友评论

        本文标题:spring boot集成dubbo

        本文链接:https://www.haomeiwen.com/subject/mkzshctx.html