1、引入jar包:
<!-- Spring Boot Dubbo 依赖 --> <dependency> <groupId>com.alibaba.spring.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>2.0.0</version> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.13</version> </dependency>
2、引入公共的jar包(服务生产者提供的jar包)
<!-- 引用akucun-api --> <dependency> <groupId>com.akucun</groupId> <artifactId>akucun-api</artifactId> <version>${akucun-api.version}</version> </dependency>
3、生产者服务的配置:
## dubbo springboot 配置 spring.dubbo.application.id=live-dubbo-provider spring.dubbo.application.name=live-dubbo-provider spring.dubbo.registry.address=zookeeper://127.0.0.1:2181 spring.dubbo.server=true spring.dubbo.protocol.name=dubbo spring.dubbo.protocol.port=20880
4、生产者的使用
1)在springboot的启动类添加@EnableDubboConfiguration注解
@EnableDubboConfiguration @SpringBootApplication public class DubboServerApplication { public static void main(String[] args) { SpringApplication.run(DubboServerApplication.class, args); } }
2)在接口的实现上加@Service注解来暴露服务(注意是dubbo的@Service,而不是spring的)
5、消费者服务配置:
# dubbo spring.dubbo.application.name=delivery-v2 spring.dubbo.registry.protocol=zookeeper spring.dubbo.registry.address=172.19.1.161:2181,172.19.1.162:2181,172.19.1.163:2181 spring.dubbo.protocol.name=dubbo spring.dubbo.consumer.version=1.0.0 spring.dubbo.consumer.check=false
6、消费者的使用
1)同样在springboot的启动类添加@EnableDubboConfiguration注解
2)服务消费方使用@Reference注解来引用服务(注意是dubbo的,而不是spring的)