标签:users autowired ott gap localhost style sys blog span
1.服务提供者:被其他微服务调用的微服务
2.服务消费者:调用的其他微服务的微服务
【服务提供】provide:8080端口
@RestController @RequestMapping("sysUserWeb2") public class SysUserWeb2 { @Resource private SysUserService2 SysUserService2; @RequestMapping("/getAll") @ResponseBody public List<SysUser>findAll2(){ return SysUserService2.findAll2(); } @RequestMapping("/findSysUserName") @ResponseBody public SysUser findSysUserName(String name){ return SysUserService2.findSysUserName(name); } }
【服务消费】customer :8081端口
@RestController public class Controller { @Autowired private RestTemplate restTemplate; @GetMapping("/findSysUserName/{name}") public SysUser findSysUserName(@PathVariable String name){ return restTemplate.getForObject("http://localhost:8080/sysUserWeb2/findSysUserName?name="+name,
SysUser.class); } }
@SpringBootApplication public class SpringBooTemplateApplication { @Bean public RestTemplate restTemplate(){ return new RestTemplate(); } public static void main(String[] args) { SpringApplication.run(SpringBootTemplateApplication.class, args); } }
@GetMapping("/findSysUserName/{name}")
描述:出现于spring4.3之后,源码中效果相当于:@RequestMapping(value="findSysUserName",method=RequestMethod.GET)
标签:users autowired ott gap localhost style sys blog span
原文地址:http://www.cnblogs.com/xxt19970908/p/6815555.html