找不到类型为'org.springframework.http.codec.ServerCodecConfigurer'的bean

时间:2018-09-21 15:49:11

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

申请无法开始


说明:

modifyRequestBodyGatewayFilterFactory中方法org.springframework.cloud.gateway.config.GatewayAutoConfiguration的参数0需要找不到类型为'org.springframework.http.codec.ServerCodecConfigurer'的bean。

操作:

考虑在您的配置中定义类型为'org.springframework.http.codec.ServerCodecConfigurer'的bean。

拾取了JAVA_TOOL_OPTIONS:-agentlib:jvmhook
拾取了_JAVA_OPTIONS:-Xbootclasspath / a:“ C:\ Program Files(x86)\ HPE \ Unified Functional Testing \ bin \ java_shared \ classes \ jasmine.jar“
捡起JAVA_TOOL_OPTIONS:-agentlib:jvmhook

4 个答案:

答案 0 :(得分:10)

尝试添加以下代码。对我有用

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

答案 1 :(得分:1)

我在构建 Spring Cloud 版本 2020.0.0Keycloak 时遇到了同样的问题,似乎 Keycloak jar 文件包含对 spring-boot-start-web 的依赖 告诉 Maven 不包含默认的 spring-boot-start-web 如下解决了该问题。

<dependency>
    <groupId>org.keycloak</groupId>
    <artifactId>keycloak-spring-boot-starter</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </exclusion>
    </exclusions>
</dependency>

但我必须在 servlet jar 中包含一个 maven 依赖项,以解决 Keycloak 的其他一些要求,如下所示:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>
 </dependency>

答案 2 :(得分:0)

您可以尝试这样:

  compile ('org.springframework.cloud:spring-cloud-starter-gateway'){
        exclude module : 'spring-cloud-starter'
        exclude module : 'spring-boot-starter-webflux'
    }

答案 3 :(得分:0)

这里有同样的问题,但解决方案

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

只隐藏问题,让应用程序编译。无论如何,它使我的网关无法正常工作。如果我使用 yaml url 中定义的请求,它不会转发、记录和响应任何内容。应用程序刚刚启动,仅此而已。

就我而言,问题是 spring-boot-start-web 依赖性。偶然我没有发现它,因为在我的项目结构中,我的 build.gradle 由“父”继承,而该父在子项目中实现了 spring-boot-start-web

我删除了那个依赖项,因为我的请求被正确转发并且我看到了日志。比我用 @Bean 删除了 ServerCodecConfigurer

希望它可以帮助任何遇到相同情况的人。

配置: 弹簧靴:2.4.4
春云:2020.0.2

相关问题