@SpringBootApplication
@EnableEurekaClient
@RestController
@EnableFeignClients //开启feign
public class DemoApplication {
@Autowired
HelloClient 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方法