标签:信息 class div bean component client dubbo cubator col
1.版本匹配问题
dubbo官网上是有说明的,也有具体的例子。https://github.com/apache/incubator-dubbo-spring-boot-project
1.x版本的springboot需要对应0.1版本的dubbo-spring-boot-starter跟较低版本的dubbo。
2.x版本的springboot对应0.2版本的dubbo-spring-boot-starter跟2.6.x版本的dubbo。
至于zookeeper倒是没有明确规定。
2.包说明
<dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> <version>0.1</version> </dependency>
zkclient包服务提供者有就行了,服务消费者可以不打。
其他的,依照官网,需要打的starter也有不同:
2.x的话要打三个包:
<dependency> <groupId>com.alibaba.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>0.2.0</version> </dependency> <!-- Dubbo --> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.6.5</version> </dependency> <!-- Spring Context Extras --> <dependency> <groupId>com.alibaba.spring</groupId> <artifactId>spring-context-support</artifactId> <version>1.0.2</version> </dependency>
1.x的话只打那个starter就可以了(注意要0.1.0的)。
还有,0.2.1的包经常搜不到,所以我打了0.2.0的,但是官网最新的是0.2.1。
3.不同版本的配置
体现在dubbo的service、reflect、跟配置信息的不同。
1.x版本:
服务提供者:
# dubbo springboot 配置 dubbo.application.name=dubbo-provider dubbo.registry.address=zookeeper://127.0.0.1:2181 dubbo.scan.base-packages=com.chriswei.bean
@Service @Component public class helloProviderimpl implements helloProvider {}
服务消费者:
# dubbo springboot 配置 dubbo.application.name=live-dubbo-comsumer dubbo.registry.address=zookeeper://127.0.0.1:2181
public class HelloConsumer { @Reference private helloProvider hello; }
1.x版本这么匹配就算是能用了,控制台会打印出你发布出去的服务,以包全名形式,当然你可以打开zkCli.cmd,输入ls /查看一下你的服务发布出去没有。
2.x版本的话,依据官方示例:
服务提供者:
# Spring boot application spring.application.name = dubbo-provider-demo server.port = 9090 management.port = 9091 # Base packages to scan Dubbo Components (e.g., @Service, @Reference) dubbo.scan.basePackages =com.chriswei.bean # Dubbo Config properties ## ApplicationConfig Bean dubbo.application.id = dubbo-provider-demo dubbo.application.name = dubbo-provider-demo ## ProtocolConfig Bean dubbo.protocol.id = dubbo dubbo.protocol.name = dubbo dubbo.protocol.port = 12345 ## RegistryConfig Bean dubbo.registry.id = my-registry dubbo.registry.address = zookeeper://127.0.0.1:2181
@Service( version = "1.0.0", application = "${dubbo.application.id}", protocol = "${dubbo.protocol.id}", registry = "${dubbo.registry.id}" ) @Component public class helloProviderimpl implements helloProvider {}
服务消费者:
# Spring boot application spring.application.name = dubbo-consumer-demo server.port = 8082 management.port = 8083 # Dubbo Config properties ## ApplicationConfig Bean dubbo.application.id = dubbo-consumer-demo dubbo.application.name = dubbo-consumer-demo ## ProtocolConfig Bean dubbo.protocol.id = dubbo dubbo.protocol.name = dubbo dubbo.protocol.port = 12345
@Service public class HelloConsumer { @Reference(version = "1.0.0", application = "${dubbo.application.id}", url = "dubbo://localhost:12345") private helloProvider hello; }
特别要注意dubbo://localhost:12345这个写法,这里就这么写,而不能写zookeeper://127.0.0.1:2181。
标签:信息 class div bean component client dubbo cubator col
原文地址:https://www.cnblogs.com/chrisweiii/p/10189818.html