RPC服务框架dubbo(六):Consumer搭建过程

时间:2021-01-15 07:56:29

1.在pom.xml中除了ssm的依赖添加dubbo相关3个依赖(接口,dubbo.jar,zkClient)

2.web.xml中修改<init-value>applicationContext-*.xml

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:applicationContext-*.xml</param-value>

</context-param>

3.spring配置文件命名为applicationContext-spring.xml,配置dubbo的配置文件applicationContext-dubbo.xml

<!-- 给当前Provider自定义个名字 -->

<dubbo:application name="dubbo-consumer"/>

<!-- 配置注册中心  -->

<dubbo:registry address="192.168.139.130:2181" protocol="zookeeper"></dubbo:registry>

<!-- 配置注解扫描 -->

<dubbo:annotation package="com.bjsxt.service.impl"/>

4.不需要编写mapper

5.除了ServiceImpl中引用Provider中接口对象改变,其他代码都一样.

@Service

public class TestServiceImpl implements TestService {

// @Resource

// private xxMapper xxxMapper;

@Reference

private DemoService demoService;