http://bbs.springcloud.cn/d/134-feign-client

server端申明

@RestController
public 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.name
public interface HelloFeginClient {

@RequestMapping(value = "/hello", method=RequestMethod.POST)
public String hello(User user);  
  
}

client 调用申明

@RestController
public 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);  
}
}
posted on 2017-05-05 11:10  一天不进步,就是退步  阅读(9038)  评论(0编辑  收藏  举报