spring-boot Feign

来源:互联网 发布:vb str是什么意思 编辑:程序博客网 时间:2024/06/04 00:22
@SpringBootApplication@EnableEurekaClient@RestController@EnableFeignClients  //开启feignpublic class DemoApplication {@AutowiredHelloClient client;@GetMapping("/hello/{name}")public String hello(@PathVariable String name){System.out.println(name+" welcome . My is microservice provider user");return name+" welcome . I'm microservice provider user";}@RequestMapping("/say")public String hello() {return client.hello();}@FeignClient("provider-user")interface HelloClient {@GetMapping("/add")String hello();}public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}}

@RequestMapping("/add")public String hello2() {   return "Hello";}
Feign接口的请求映射需与注册到eureka的服务的请求地址(/add)一致,方法名可不一致,
当请求/say,则会请求到hello2方法