Dubbo Spring Boot Starter。也可以关注dubbo官方的dubbo-spring-boot-project
支持jdk版本为1.6或者1.6
(在修改源码前,请导入googlestyle-java.xml以保证一致的代码格式)
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
spring.application.name=dubbo-spring-boot-starter
spring.dubbo.server=true
spring.dubbo.registry=N/A
注:这个配置只针对服务提供端,消费端不用指定协议,它自己会根据服务端的地址信息和@Reference注解去解析协议
@EnableDubboConfiguration
,表示要开启dubbo功能. (dubbo provider服务可以使用或者不使用web容器) @SpringBootApplication
@EnableDubboConfiguration
public class DubboProviderLauncher {
//...
}
@Service
(import com.alibaba.dubbo.config.annotation.Service)注解,其中interfaceClass是要发布服务的接口. @Service(interfaceClass = IHelloService.class)
@Component
public class HelloServiceImpl implements IHelloService {
//...
}
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
spring.application.name=dubbo-spring-boot-starter
@EnableDubboConfiguration
@SpringBootApplication
@EnableDubboConfiguration
public class DubboConsumerLauncher {
//...
}
@Reference
注入需要使用的interface. @Component
public class HelloConsumer {
@Reference(url = "dubbo://127.0.0.1:20880")
private IHelloService iHelloService;
}
本文由低调小熊猫一文多发操作发布! 欢迎关注公众号:低调小熊猫