错误描述
Description:
Field FeignClient in xx required a bean of type 'org.springframework.cloud.openfeign.FeignContext' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'org.springframework.cloud.openfeign.FeignContext' in your configuration.
原因
版本冲突。之前SpringBoot版本用的2.5.3没这个问题,升级到3.0.1之后报错[1]
因为Spring Boot 3.0.0 中的Spring.factories被移除,所以之前的版本配置失败了。
解决
在启动类之前加上
@ImportAutoConfiguration({FeignAutoConfiguration.class})
尝试再次启动报错
可能因为Feign的自动配置需要db依赖,我直接在pom中加上
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
之后顺利启动