Springboot整合dubbo的三种方式
目录
1、使用xml配置文件
导入dubbo-starter依赖
使用这种方式需要在启动类加一个注解:
@ImportResource(locations="classpath:provider.xml")
例如:
配置提供者
<!--当前应用的名字 -->
<dubbo:application name="gmall-user"></dubbo:application>
<!--指定注册中心的地址 -->
<dubbo:registry address="zookeeper://118.24.44.169:2181" />
<!--使用dubbo协议,将服务暴露在20880端口 -->
<dubbo:protocol name="dubbo" port="20880" />
<!-- 指定需要暴露的服务 -->
<dubbo:service interface="com.atguigu.gmall.service.UserService" ref="userServiceImpl" />
配置消费者信息
<!-- 应用名 -->
<dubbo:application name="gmall-order-web"></dubbo:application>
<!-- 指定注册中心地址 -->
<dubbo:registry address="zookeeper://118.24.44.169:2181" />
<!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
<dubbo:reference id="userService" interface="com.atguigu.gmall.service.UserService"></dubbo:reference>
详细的配置信息可以从dubbo官网中查看:
2、使用注解的方式
导入dubbo-starter
使用这种方式的前提是在applicant.properties进行一些相关的配置。如
dubbo.application.name=provider
demo.service.version =1.0.0
dubbo.protocol.name=dubbo
dubbo.protocol.port=20880
dubbo.registry.protocol=zookeeper
dubbo.registry.address=192.168.137.3:2181
dubbo.provider.timeout=1000
然后可以使用