Feign踩坑

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘projectServiceController’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘xServiceImpl’: Unsatisfied dependency expressed through field ‘xService’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘com.wzb.businessservice.service.xDBService’: FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Method insInitial not annotated with HTTP method type (ex. GET, POST)

未声明GET还是POST请求方式,在feign api和具体实现(同一个url的controller)中需要全部声明请求方式

2019-09-28 17:49:51.847 ERROR 16500 — [nio-9091-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: com.netflix.client.ClientException: Load balancer does not have available server for client: EUREKA-DB-PROVIDER] with root cause

未找到名为 EUREKA-DB-PROVIDER的服务

@FeignClient(value = "EUREKA-DB-PROVIDER")
//@FeignClient(value = "EUREKA_DB_PROVIDER") //非法服务名不能带下划线

2019-09-28 17:56:20.283 ERROR 36456 — [nio-9091-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is feign.FeignException$NotFound: status 404 reading xDBService#selAll()] with root cause

requestmapping映射出错

//service中的feign包
import org.springframework.cloud.netflix.feign.FeignClient;

//consumer中的feign包
import org.springframework.cloud.openfeign.EnableFeignClients;

导包不正确错处无法检测

Consider defining a bean of type ‘com.x.dbservice.xDBService’ in your configuration.

失败原因:导包错误,接口实现要和feign的API分开,接口不应该被注解为FeignClient否则会出现和controller中的实现有同名url的错误,API必须重新定义指向注册到eureka中的服务,并且服务尽量不要用下划线进行连接,spring不支持搜寻下划线连接的任务

这个错误有些莫名其妙


<dependency>
    <groupId>org.springframework.cloudgroupId>
    <artifactId>spring-cloud-starter-feignartifactId>
    <version>1.4.1.RELEASEversion>
dependency>

明明导入了同样的包但是单独导入此包和连带着springboot与springcloud默认的一些配置一同导入最后import的@EnableFeignClients注解居然不是在同一个包下的,如果单独导入feign那么不管是FeignClient还是@EnableFeignClients注解都是org.springframework.cloud.netflix.feign包下的类,然而带着spring初始化环境再导入上述feign则会变为org.springframework.cloud.openfeign包下的类,因为这个问题纠结了一整天,虽然都是feign但是不在同一包下可能是不同的版本或者实现,所以无法混合调用导致出错报错为无法找到API的实现类无法实现注入Consider defining a bean of type ‘FeignAPI’ in your configuration.

单独导入feign,maven也会报错

你可能感兴趣的:(springcloud,java)