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