bean of type 'org.springframework.http.codec.ServerCodecConfigurer' that could not be found

Viewed 21921

APPLICATION FAILED TO START


Description:

Parameter 0 of method modifyRequestBodyGatewayFilterFactory in org.springframework.cloud.gateway.config.GatewayAutoConfiguration required a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' that could not be found.

Action:

Consider defining a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' in your configuration.

Picked up JAVA_TOOL_OPTIONS: -agentlib:jvmhook
Picked up _JAVA_OPTIONS: -Xbootclasspath/a:"C:\Program Files (x86)\HPE\Unified Functional Testing\bin\java_shared\classes\jasmine.jar"
Picked up JAVA_TOOL_OPTIONS: -agentlib:jvmhook

6 Answers

Try adding the below code. It worked for me

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

You can try like this:

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

I had the same issue building a spring cloud version 2020.0.0 and Keycloak, it seems that the Keycloak jar files includes a dependency on spring-boot-start-web Telling maven NOT to include the default spring-boot-start-web as follows resolved that issue.

<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>

But I had to include a maven dependency to the servlet jar as to resolve some other requirements of Keycloak as follows:

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

Same issue here but solution with

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

only hid problem, and let application to compile. Anyway Somehow it made my Gateway not working correct. It didn't forward, log and response anything if I request with defined in yaml urls. Application just started and that's it.

In my case problem was spring-boot-start-web dependency. Accidently I didn't discover it, because in my project structure, my build.gradle inherits by "parent" and that parent implemented spring-boot-start-web in subprojects.

I removed that dependency and since than I requests were forwarded correctly and I saw logs. Than i removed @Bean with ServerCodecConfigurer .

Hope it could help anyone in same situation.

Configuration: Spring boot: 2.4.4
Spring cloud: 2020.0.2

For me the problem was that I added the dependency:

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-core</artifactId>
    <version>10.1.0-M4</version>
</dependency>

Pay attention if you are using Reactive Spring. I needed HttpServletRequest from this dependency, but now I'm using ServerHttpRequest from org.springframework.http.server.reactive.

In the application.properties file, set this property spring.main.web-application-type=reactive.

Related