您现在的位置是:首页 > 文章详情

Java B2B2C多用户商城 springboot架构-SpringCloud服务相互调用RestTemplate

日期:2018-12-17点击:348

Springcloud中的服务消费,就需要我们服务之前相互发请求了。之前我们都是想着用http请求相关的交互,用的比较多的是apache httpcomponents ,现在springboot提供了RestTemplate更高级别的方法来满足我们的功能。

需要JAVA Spring Cloud大型企业分布式微服务云构建的B2B2C电子商务平台源码请加企鹅求求 :二一四七七七五六三三

RestTemplate 的类路径
org.springframework.web.client.RestTemplate
其实我们之前就已经集成过了,在spring-boot-starter-web中已经有了它的依赖。

Maven

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> 

Biz服务

@RestController @RequestMapping("index") public class IndexController { @Resource private UserService userService; @RequestMapping("findUserMenuList") public Object findUserMenuList(){ return userService.findUserMenuList("李文涛"); } } 

Biz-2服务具体调用如下

@RestController @RequestMapping("index") public class IndexController { @Autowired private RestTemplate restTemplate; String host = "http://SERVICE-BIZ"; //biz服务的名称,大小写忽略 @RequestMapping("index") public Object index(){ String url = host+"/index/findUserMenuList"; Map<String,Object> uriVariables = new HashMap<>(); return restTemplate.getForObject(url,Object.class); } } 

Biz-2调用的前提是,注册中心启动了,Biz服务也启动了,这样就OK了。

springboot微服务多用户商城系统java_代码开源_B2B电商系统_B2C电商系统

原文链接:https://yq.aliyun.com/articles/680164
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章