1.背景:现有springcloud项目已使用的注册中心,并不想再使用zk作为注册中心,内部不同集群(不在同一个注册中心的集群)直接的交互无法使用springcloud的feign 调用,直接发送Http不方便,最终决定使用Dubbo
2.springboot 集成dubbo,使用配置文件的方式
dubbo-customer.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="springboot-consumer"/>
<!-- 集群下url可疑指定多个逗号分隔例如:dubbo://127.0.0.1:20880,dubbo://127.0.0.1:20881 -->
<dubbo:reference id="testService" version="1.0.0" interface="com.yyf.dubbo.inf.TestService" url="dubbo://127.0.0.1:20880"/>
</beans>
springboot 启动类上加上@ImportResource(value = {"classpath:dubbo-customer.xml"})
dubbo-provider.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="springboot-provider" />
<dubbo:annotation package="com.yyf.dubbo.provider.service"></dubbo:annotation>
<dubbo:protocol name="${dubbo.name}" port="${dubbo.port}"></dubbo:protocol>
<!-- 弃用注册中心 -->
<dubbo:registry address="N/A" />
<dubbo:service ref="testServiceImpl" interface="com.yyf.dubbo.inf.TestService" version="1.0.0"></dubbo:service>
</beans>
<dubbo:registry address="N/A" /> 不使用注册中心时 registry address 一定要设置为N/A
@ImportResource(value = {"classpath:dubbo-provider.xml"})
参考地址:
https://blog.csdn.net/u011123972/article/details/89357053
https://blog.csdn.net/qw463800202/article/details/82222771
https://blog.csdn.net/weixin_44946117/article/details/91869171
https://blog.csdn.net/lchpersonal521/article/details/81837583
https://blog.csdn.net/weixin_36898373/article/details/105545066
https://blog.csdn.net/ys3909656/article/details/89674923
https://www.pianshen.com/article/3719367973/