spring boot集成dubbo
2019-07-05 本文已影响5人
异类_8b7a
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);
}
}