使用spring boot构建的客户端项目wolf调用dubbo服务

lion:dubbo服务的提供方,即服务端

项目地址:https://github.com/BruceZhangXL/lion

wolf:dubbo服务的调用方,即客户端
项目地址:https://github.com/BruceZhangXL/wolf

wolf项目也是基于spring boot搭建的,结构和lion类似,下面我主要说下,对dubbo服务的调用,作为客户端这一侧,要做哪些配置。

1、在wolf-rpc模块依赖服务端的一些接口jar包,主要是lion-domain和lion-export
2、在wolf-rpc中增加dubbo调用侧的一些配置spring-dubbo.xml,spring-goods-consumer.xml
其中spring-dubbo.xml文件中主要放置的是对注册中心的一些参数配置,内容如下:

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
">




spring-goods-consumer.xml中主要是对远端提供侧服务的配置,内容如下

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
">

3、在service层使用这个helloService
@Service("itemService")
public class ItemServiceImpl implements ItemService{
@Resource
private ItemDraftMapper itemDraftMapper;

@Resource
private HelloService helloService;

使用@Resource注入该远端服务(实际上此时注入的是远端服务的一个代理类)

4、增加测试controller

@Controller
@RequestMapping("dubbo")
public class DubboTestController {
@Resource
private ItemService itemService;

@RequestMapping("")
@ResponseBody
public HelloDomain sayHi(String name){
    return itemService.sayHi(name);
}

}

5、修改wolf项目端口为8082,启动项目后测试


image.png

6、看看duboo-admin上,客户端是否注入

下图可以看到客户端项目wolf已经可以看到了。


image.png

你可能感兴趣的:(使用spring boot构建的客户端项目wolf调用dubbo服务)