@FeignClient(value = "user-service")
public interface UserClient {
//http://user-service/user/123
@GetMapping("/user/{id}")
User queryById(@PathVariable int id);
}
配置完后再运行这个消费服务的时候抛出了一个异常
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'consumerFeignController': Unsatisfied dependency expressed through method 'setUserClient' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.consumer.client.UserClient': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
后来在Stack Overflow找到了解决办法,它的大概意思就是你正在使用一个老的版本,应该将pathVariable的name写到@PathVariable注解当中
具体细节请看@PathVariable not working with feign · Issue #861 · spring-cloud/spring-cloud-netflix · GitHub
@RequestMapping(value = "/hello/{name}", method = RequestMethod.GET)
String hello(@PathVariable(value = "name") String name);


