一、新建项目
新建项目,只放置接口,用于暴露 Dubbo 服务接口
1 | public interface GreetingService { |
二、provider
本文以上文中的 Service1 作为 provider,以 Service2 作为 consumer
2.1 添加依赖
1 | <dependency> |
2.2 实现接口
1 | @Service |
@Service 为 org.apache.dubbo.config.annotation.Service (旧的版本为 com.alibaba.dubbo.config.annotation.Service),此处的 @Service 只能供 Dubbo RPC 调用,如果需要像之前一样正常在 Controller 层调用需要再添加 @Component 注解 (或者直接不添加 @Component 在项目内也通过 Dubbo 调用)
2.3 新增配置
1 | dubbo: |
三、consumer
3.1 调用服务
1 | @Reference |
@Reference 为 org.apache.dubbo.config.annotation.Reference (旧的版本为 com.alibaba.dubbo.config.annotation.Reference)
3.2 新增配置
1 | dubbo: |
启动服务,访问 http://localhost:8079/dubboGreeting 可以看到结果