feign 注入失败及 Unexpected exception during bean creation; nested exception is java.lang.IllegalStateE问题
问题:A component required a bean of type 'com.yp.octobus.octobusjobapi.service.FeignJobInfoService' that could not be found.解决办法://@EnableFeignClients(clients = { FeignJobInfoService.class }) //方法1@Enab
·
问题:
A component required a bean of type 'com.atao.project.feign.FeignJobInfoService' that could not be found.
解决办法:
启动类中增加注解@EnableFeignClients
//@EnableFeignClients(clients = { FeignJobInfoService.class }) //方法1
@EnableFeignClients(basePackages = "com.atao.project.feign")//方法2
这时又出现了新的问题:
Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?
原因:
SpringCloud Feign在Hoxton.M2 RELEASED版本之后不再使用ribbon
而是使用spring-cloud-loadbalancer,所以在不引入spring-cloud-loadbalancer情况下会报错
解决办法:修改pom文件,增加loadbalancer
<!-- 负载均衡-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
<version>3.0.3</version>
</dependency>
ps:我这里nacos、feign版本:
<!--openfeign-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>3.0.1</version>
</dependency>
<!-- 引入nacos依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2021.1</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>2021.1</version>
</dependency>
OK,解决
更多推荐
已为社区贡献1条内容
所有评论(0)