Feign报错‘org.springframework.cloud.openfeign.FeignContext‘ that could not be found.

6 篇文章 0 订阅
4 篇文章 0 订阅

错误描述

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>

之后顺利启动


参考:
[1]Consider defining a bean of type ‘org.springframework.cloud.openfeign.FeignContext’ in your configuration

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
错误信息"A component required a bean of type 'org.springframework.cloud.openfeign.FeignContext' that could not be found."表示在启动应用程序时无法找到类型为"org.springframework.cloud.openfeign.FeignContext"的bean。这种情况通常出现在使用Spring Cloud OpenFeign作为微服务之间的通信框架时。根据引用和引用的信息,这种错误可能是由于缺少必需的依赖项或配置问题引起的。 解决此问题的一种方法是确保您的项目中包含了正确的依赖项。请确保您的项目中已经添加了相应的Spring Cloud OpenFeign依赖。您可以检查您的构建文件(例如pom.xml或build.gradle)以确保已正确声明了相关依赖项,并且版本与您的Spring Boot版本兼容。 另一种常见的解决方法是在应用程序的配置类中手动创建FeignContextbean。根据引用中的信息,您可以在启动类中添加以下代码来创建该bean: ```java import org.springframework.cloud.openfeign.FeignContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class FeignConfig { @Bean public FeignContext feignContext() { return new FeignContext(); } } ``` 通过以上配置,您可以手动创建一个FeignContext的实例并将其纳入到应用程序的上下文中,以解决"A component required a bean of type 'org.springframework.cloud.openfeign.FeignContext' that could not be found."的错误。 请注意,具体的解决方法可能因您的项目结构和配置而有所不同。如果上述方法无法解决问题,请检查您的代码和配置文件,确保正确配置了FeignContext的依赖项和bean。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [一个诡异的A component required a bean of type异常](https://blog.csdn.net/louis_lee7812/article/details/127460667)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [问题及解决方法记录:A component required a bean of typeorg.springframework.web.client....](https://blog.csdn.net/habuz/article/details/120553689)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值