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