zoukankan      html  css  js  c++  java
  • spring cloud spirng整合feign

    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();
    	}
    }
    

      

  • 相关阅读:
    20170705总结
    20170703总结
    .NET 框架程序使用 Win32 API
    青春 就此别过
    Aptana Studio 2启动时提示 Workspace Cannot Be Created 解决办法
    App_GlobalResources.afvubzdv.resources.dll”--“拒绝访问。“
    c# 一维数组和二维数组的定义几种方式<转>.
    C#中Split分隔字符串的应用(C#、split、分隔、字符串)<转>
    C#操作字符串方法总结<转>
    C# 时间格式大全
  • 原文地址:https://www.cnblogs.com/zfzf1/p/8543266.html
Copyright © 2011-2022 走看看