🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 一、准备工作 dubbo依赖于zookeeper作为服务注册中心,所以,需要先安装zookeeper; 参考:[运行容器/zookeeper/安装运行](../zookeeper/%E5%AE%89%E8%A3%85%E8%BF%90%E8%A1%8C.md) ### **引入依赖:** ``` <dependency> <groupId>com.alibaba.spring.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>2.0.0</version> </dependency> ``` ### **配置文件:** ``` spring.dubbo.server=true spring.dubbo.registry=N/A ``` ## 二、代码开发 ### **服务端** Spring Boot Application的上添加`@EnableDubboConfiguration`,表示要开启dubbo功能; ``` @EnableDubboConfiguration public class RayApp { public static void main(String... strings) { RayframeworkApplication.startUp(strings); } } ``` 接口定义: ``` public interface RayDubboService { String testMethdo(); } ``` 服务发布: ``` @Service(interfaceClass = RayDubboService.class) @Component public class RayDubboServiceImpl implements RayDubboService { @Override public String testMethdo() { return "Hello,dubbo!"; } } ``` ### **消费端** Spring Boot Application的上添加`@EnableDubboConfiguration`,表示要开启dubbo功能; ``` @EnableDubboConfiguration public class RayApp { public static void main(String... strings) { RayframeworkApplication.startUp(strings); } } ``` 接口定义: ``` public interface RayDubboService { String testMethdo(); } ``` 服务使用: ``` @Component public class RayDubboConsumerSample{ @Reference(url = "dubbo://127.0.0.1:20880") private RayDubboService rayDubboService; } ```