cloud组件之(OpenFeign坑)
opengin使用步骤:
接口+注解(@FeignClient)
主启动类加上@EnableFeignClients
找错1半小时才找到!!!!!!
错误写法:
@Component
@FeignClient(value = "CLOUD-PAYMENT-SERVICE")
public interface OrderService {
@GetMapping(value = "/getpaymentById/{id}")
Map getpaymentById(@PathVariable Integer id);
}
会报错:
2020-06-17 17:17:44.754 WARN 5948 — [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘orderController’: Unsatisfied dependency expressed through field ‘orderService’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘com.zsp.springcloud.service.OrderService’: FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
报错原因:
@PathVariable Integer id 错误写法导致报错
@PathVariable(“id”) Integer id 正确写法
正确写法:
@Component
@FeignClient(value = "CLOUD-PAYMENT-SERVICE")
public interface OrderService {
@GetMapping(value = "/getpaymentById/{id}")
Map getpaymentById(@PathVariable("id") Integer id);
}