栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

五.springboot集成dubbo(无admin)

五.springboot集成dubbo(无admin)

  • 先搭建两个微服务工程provider/consumer
1.pom.xml org.springframework.boot spring-boot-starter-parent 2.0.4.RELEASE org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-devtools test org.springframework.boot spring-boot-maven-plugin 2.application.properties--provider spring.application.name = dubbo-spring-boot-provider/consumer 2.application.properties--consumer spring.application.name = dubbo-spring-boot-consumer server.port = 8084 3。创建启动类ProviderApplication/ConsumerApplication @SpringBootApplication public class ProviderApplication{ public static void main(String[] args) { SpringApplication.run(ProviderApplication.class, args); } } 4.创建访问接口 @Controller @RequestMapping public class HelloController { @RequestMapping("/getHello") @ResponseBody public String getHello(){ return "hello my springboot"; } } 5.分别main方法启动启动类
  • provider项目配置修改
1.引入dubbo依赖 com.alibaba.spring.boot dubbo-spring-boot-starter 2.0.0 2.启动类添加注解 @EnableDubboConfiguration 3.application.properties spring.dubbo.registry=N/A spring.dubbo.server=true 4.添加业务处理接口 public interface DubboService { public String getName(String name); } import com.alibaba.dubbo.config.annotation.Service; import com.example.service.DubboService; import org.springframework.stereotype.Component; @Component //spring的bean配置 @Service(interfaceClass = DubboService.class) //相当于dubbo:service interface暴露配置 public class DubboServiceImpl implements DubboService{ @Override public String getName(String name) { return "姓名:"+name; } } 5.main方法启动启动类
  • consumer项目配置修改
1.引入dubbo依赖 com.alibaba.spring.boot dubbo-spring-boot-starter 2.0.0 2.启动类添加注解 @EnableDubboConfiguration 3.添加业务处理接口 public interface DubboService { public String getName(String name); } 4.修改consumer访问接口 import com.alibaba.dubbo.config.annotation.Reference; import com.example.service.DubboService; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; @Controller @RequestMapping public class TestController { @Reference(url = "dubbo://localhost:20880") DubboService dubboService; @ResponseBody @RequestMapping(value = "/abc",method = RequestMethod.GET) public String abc(String name){ // return "nihao"; return dubboService.getName(name); } } 5.main方法启动启动类 访问 http://localhost:8084/abc?name=ninds
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/488053.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号