Gateway error Unable to start ServletWebServerApplicationContext due to missing ServletWebServer

Problem error:

Error 1:

org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'conversionServicePostProcessor' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Cannot register bean definition [Root bean: class [org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=conversionServicePostProcessor; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]] for bean \ 'conversionServicePostProcessor': There is already [Root bean: class [org.springframework.security.config.annotation.web.reactive.WebFluxSecurityConfiguration]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=conversionServicePostProcessor; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/security/config/annotation/web/reactive/WebFluxSecurityConfiguration.class] ] bound.
at org.springframework.beans.factory.support.DefaultListableBeanFactory.registerBeanDefinition(DefaultListableBeanFactory.java:945)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:286)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:144)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:120)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:280)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)

Error 2:

org.springframework.http.codec.ServerCodecConfigurer’ that could not be found

Problem analysis:

This error means that the ServeltWebServer bean was not found, and it is obvious that this bean is about the web. So we have to start from this direction. If the bean cannot be found, either the web service is not configured, the bean is not configured, or a conflict occurs.

Problem solved:

Normal services:

If it is an ordinary project, it basically lacks the web service.

Solution 1:

pom file configuration

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

Solution 2:

See if the class you wrote in the startup class is consistent.

?

Solution 3:

Whether @SpringBootApplication is configured

?

Gateway gateway service:

Solution 1:

For spring cloud gateway, it is based on webflux rather than web framework. Therefore, importing pom requires importing

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>

If there is a web, you need to delete the pom coordinates. Or you need to remove the coordinates when introducing other projects that contain the pom file.

?

Solution 2 (the one the blogger thinks is most useful):

In fact, I have tried all the above solutions, but they just don’t work. After importing this webflux, other strange errors will still be reported. After removing them through the exclusions keyword, other errors will be reported. This proves that this is not the case.

So just configure the following directly in the configuration file

spring:
  main:
    web-application-type: reactive

Principle:

When set to reactive, Spring Boot will use the reactive programming model to build applications. Reactive programming is an asynchronous programming paradigm that focuses on data flow and change propagation. This means it can handle non-blocking I/O better, making your application more scalable and responsive. This setup is typically used with Spring WebFlux, a new reactive web framework introduced with Spring 5.0. It can coexist with the traditional Servlet API (via the web-application-type: servlet setting), or run as a standalone reactive stack. In general, the role of web-application-type: reactive is to allow Spring Boot applications to use a reactive programming model to improve application performance and scalability.


The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. Java Skill TreeHomepageOverview 138,609 people are learning the system