<dubbo:reference>
没定义 id
,默认不会暴露这个 Bean 给 Spring 注入;故在spring中集成dubbo,在消费端一定要定义这个id;
然后集成的主要步骤:
第一点:
<!-- Apache Dubbo 核心 -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>2.7.13</version>
</dependency>
<!-- Dubbo与zookeeper的整合配置自动引入相关依赖包-->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>2.7.13</version>
<type>pom</type>
</dependency>
第二点:
@ImportResource(locations = {"classpath:dubbo/spring-dubbo.xml"})
也可以借助@Profile指定不同环境的
@Configuration
@ImportResource(locations = {"classpath:dubbo/spring-dubbo-dev.xml"})
@Profile("dev")
public class DubboDevConfiguration {
}
第三点:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
default-autowire="byName"
xmlns="http://www.springframework.org/schema/beans"
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="manage-${spring.profiles.active}"/>
<dubbo:registry protocol="zookeeper" address="xx.xx.cc:110,xx.xxx.cc:110,xxx.xx.cc:30002" />
<dubbo:reference id="dealerScService" check="false" lazy="true" interface="com.xx.xx.oms.api.DealerScService" version="1.0.0" group="dev" />
</beans>