http://bbs.springcloud.cn/d/134-feign-client
server端申明
@RestControllerpublic class HelloController { private Logger log = LoggerFactory.getLogger(HelloController.class); /** * rest 服务用来测试 * --@requestParam url?xxx=name * --requestBody 认定为json传输解析 url?{xxx=name} * @param name * @return */ @RequestMapping(value = "/hello", method = RequestMethod.POST) public String hello(@RequestBody User user) { log.info("call hello parameter:{}", user.getName()); return "{hello: '" + user.getName() + "'}"; } }
feginClient申明
@FeignClient(value="HelloServer") //对应到的server端的spring.application.namepublic interface HelloFeginClient { @RequestMapping(value = "/hello", method=RequestMethod.POST) public String hello(User user); }
client 调用申明
@RestControllerpublic class CallHelloController { private Logger log = LoggerFactory.getLogger(CallHelloController.class); @Autowired private HelloFeginClient helloFeginClient; @RequestMapping(value="/hello", method = RequestMethod.GET) public String hello(String name) { log.info("call hello parameter:{}", name); User user = new User(); user.setName("kite"); return helloFeginClient.hello(user); } }