bean of type 'org.springframework.http.codec.ServerCodecConfigurer' that could not be found
Solution 1
Try adding the below code. It worked for me
@Bean
public ServerCodecConfigurer serverCodecConfigurer() {
return ServerCodecConfigurer.create();
}
Solution 2
You can try like this:
compile ('org.springframework.cloud:spring-cloud-starter-gateway'){
exclude module : 'spring-cloud-starter'
exclude module : 'spring-boot-starter-webflux'
}
Solution 3
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>
Solution 4
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
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on June 05, 2022Comments
-
Admin about 2 years
APPLICATION FAILED TO START
Description:
Parameter 0 of method
modifyRequestBodyGatewayFilterFactory
inorg.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 -
scruffy over 3 yearsThis worked for me but only to configure basic security within gateway. I still needed to later replace
spring-boot-start-web
withspring-boot-start-webflux
. For anyone interested, there's a nice code samples at Spring Blog -
Neo over 3 yearsHi, I'm new to Spring. Where do I add the code above to?
-
Dave about 3 yearsThe answer refers to the gradle build system, you would make the changes to a file called build.gradle. If your using mavin you would have to make changes to your pom.xml and use <exclusion> statement.
-
Zon over 2 yearsThis may happen when your application is on a non-reactive stack and you import some libraries with a reactive stack that raise some beans into Spring context. Excluding reactive HTTP transitive dependencies will help.
-
cluis92 about 2 yearsAdding this bean creates a circular dependency for me; replacing 'web' with 'webflux' (also, it should be 'starter' not 'start') as mentioned in the comment, created errors for a class I had called 'LocaleConfiguration' which had imports coming from org.springframework.web.servlet