SpringBoot整合Dubbo
Posted 关耳er
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot整合Dubbo相关的知识,希望对你有一定的参考价值。
一、导入依赖
二、生产者provider
(1)目录展示
(2)配置文件application.properties
(3)DoSomeService接口
package com.zn.service; public interface DoSomeService { public String sayHi(); }
(4)DoSomeServiceImpl实现类
package com.zn.service.impl; import com.alibaba.dubbo.config.annotation.Service; import com.zn.service.DoSomeService; import org.springframework.stereotype.Component; @Service(interfaceClass = DoSomeService.class) @Component public class DoSomeServiceImpl implements DoSomeService{ @Override public String sayHi() { System.out.println("生产者生产的IDoSomeService服务,中的sayHi方法"); return "SpringBoot Dubbo"; } }
(5)测试类StartDubbo
四、消费者consumer
(1)目录展示
(2)配置文件application.properties
(3)DoSomeService接口
package com.zn.service; public interface DoSomeService { public String sayHi(); }
(4)DubboController
package com.zn.controller; import com.alibaba.dubbo.config.annotation.Reference; import com.zn.service.DoSomeService; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class DubboController { @Reference private DoSomeService doSomeService; @RequestMapping("/dubbo") public String dubbo(){ String returnValue = doSomeService.sayHi(); return returnValue; } }
(5)测试类
五、效果展示
以上是关于SpringBoot整合Dubbo的主要内容,如果未能解决你的问题,请参考以下文章
dubbo远程调用(rpc)-->快速入门+管理控制台+整合Springboot开发
dubbo远程调用(rpc)-->快速入门+管理控制台+整合Springboot开发