【问题标题】:Exception : a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' that could not be found例外:找不到“org.springframework.http.codec.ServerCodecConfigurer”类型的bean
【发布时间】:2020-01-09 16:59:38
【问题描述】:

添加以下 maven 依赖项后,我的程序中出现以下错误。

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.2.2.RELEASE</version>

错误

通过构造函数参数2表示的不满足的依赖关系; 嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException: 否 类型的限定 bean 'org.springframework.http.codec.ServerCodecConfigurer' 可用: 预计至少有 1 个 bean 有资格作为 autowire 候选者。 依赖注释:{}

行动:

考虑在你的配置中定义一个“org.springframework.http.codec.ServerCodecConfigurer”类型的bean。

请建议如何创建 org.springframework.http.codec.ServerCodecConfigurer。


添加以下代码即可解决问题。

@Bean
public ServerCodecConfigurer serverCodecConfigurer() {
   return ServerCodecConfigurer.create();
}

【问题讨论】:

  • 参见:stackoverflow.com/questions/52447223/… 或者您可以在 org.springframework.http.codec.ServerCodecConfigurer 上进行搜索。 .
  • 分享相关代码,了解更多细节和stacktrace
  • 分享你的完整 pom.xml
  • 你试过@cliff2310提供的链接吗
  • 我已经检查了@cliff2310 链接。我不知道如何执行该编译代码。你能建议一下吗?

标签: java spring-boot javabeans spring-framework-beans


【解决方案1】:

就我而言,这是由于我的依赖项中同时包含 spring-boot-starter-webspring-cloud-starter-gateway 造成的。

在撰写本文时,这两个项目不兼容:https://github.com/spring-cloud/spring-cloud-gateway/issues/319

【讨论】:

    猜你喜欢
    • 2019-02-26
    • 2018-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-16
    • 2018-06-12
    • 2019-04-02
    • 1970-01-01
    相关资源
    最近更新 更多