1.maven配置
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<exclusions>
<exclusion>
<artifactId>spring</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- Zookeeper 用于分布式服务管理 -->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
</dependency>
<!-- Zookeeper 用于分布式服务管理 end -->
2.dubbo生产者配置
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.0.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- dubbo服务提供方 -->
<!-- 配置dubbo服务名:用于monitor监控 -->
<dubbo:application name="service-product"/>
<!-- 配置dubbo的注册中心 -->
<!--<dubbo:registry protocol="zookeeper" address="192.168.200.140:2181"/>-->
<!--dubbo直连-->
<dubbo:registry address="N/A" />
<!-- 配置dubbo协议 -->
<dubbo:protocol name="dubbo" port="20880"/>
<!-- 将接口暴露到注册中心 ref引用具体的实现类-->
<dubbo:service ref="testTbService" interface="com.kenick.sport.service.TestTbService" class="com.kenick.sport.serviceImpl.TestTbServiceImpl"/>
<dubbo:service ref="brandService" interface="com.kenick.sport.service.BrandService" class="com.kenick.sport.serviceImpl.BrandServiceImpl"/>
</beans>
3.dubbo消费者配置
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.0.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- dubbo服务消费方 -->
<!-- 配置dubbo服务名:用于monitor监控 -->
<dubbo:application name="console"/>
<!-- 配置dubbo的注册中心 -->
<!-- <dubbo:registry protocol="zookeeper" address="192.168.200.140:2181"/>-->
<!-- 配置引用注册中心的服务-->
<dubbo:reference id="testTbService" interface="com.kenick.sport.service.TestTbService" url="dubbo://127.0.0.1:20880"/>
<dubbo:reference id="brandService" interface="com.kenick.sport.service.BrandService" url="dubbo://127.0.0.1:20880"/>
<dubbo:consumer timeout="600000"/>
</beans>
4.spring加载dubbo配置文件
<!-- 加载dubbo的服务消费方法配置文件 -->
<import resource="classpath:dubbo-consumer-dev.xml"/>