码迷,mamicode.com
首页 > 编程语言 > 详细

spring cloud spirng整合feign

时间:2018-03-11 11:56:28      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:cat   ble   get   sage   post   path   iat   ace   var   

restserver

@RestController
public class PoliceController {

	@RequestMapping(value = "/call/{id}", method = RequestMethod.GET, 
			produces = MediaType.APPLICATION_JSON_VALUE)
	public Police call(@PathVariable Integer id, HttpServletRequest request) {
		Police p = new Police();
		p.setId(id);
		p.setName("angus");
		p.setMessage(request.getRequestURL().toString());
		return p;
	}
	
	@RequestMapping(value = "/hello/{name}", method = RequestMethod.GET)
	public String hello(@PathVariable String name) {
		return "Hello, " + name;
	}
	
	@RequestMapping(value = "/hellowd", method = RequestMethod.GET)
	public String helloWithOutArg() {
		return "Hello World";
	}
}

  feign client interface

@FeignClient("spring-feign-provider")
public interface HelloClient {

	@RequestMapping(method = RequestMethod.GET, value="/hello/{name}")
	String hello(@PathVariable("name") String name);
	
	
	@RequestMapping(method = RequestMethod.GET, value="/call/{id}")
	Police getPolice(@PathVariable("id") Integer id);
	
	@MyUrl(url = "/hellowd", method = "GET")
	String myHello();
}

  feign client

@RestController
public class TestController {
	
	@Autowired
	private HelloClient helloClient;

	@RequestMapping(method = RequestMethod.GET, value="/router")
	public String router() {
		String result = helloClient.hello("angus");
		return result;
	}

	@RequestMapping(method = RequestMethod.GET, value="/police", 
			produces = MediaType.APPLICATION_JSON_VALUE)
	public Police getPolice() {
		Police p = helloClient.getPolice(1);
		return p;
	}
	
	@RequestMapping(method = RequestMethod.GET, value="/myhello")
	public String myHello() {
		return helloClient.myHello();
	}
}

  

spring cloud spirng整合feign

标签:cat   ble   get   sage   post   path   iat   ace   var   

原文地址:https://www.cnblogs.com/zfzf1/p/8543266.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!