- 
                Notifications
    You must be signed in to change notification settings 
- Fork 41.6k
Description
I want to register org.springframework.web.server.i18n.LocaleContextResolver in Spring Boot 2.3.4.RELEASE.
However, the following code not working:
Example for LocaleContextResolver defination:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.server.i18n.FixedLocaleContextResolver;
import org.springframework.web.server.i18n.LocaleContextResolver;
@Configuration
public class WebConfig {
    @Bean
    public LocaleContextResolver localeContextResolver() {
        return new FixedLocaleContextResolver();
    }
}I get runtime error:
2020-09-21 09:31:47.513 ERROR 10584 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'localeContextResolver', defined in org.springframework.web.reactive.config.DelegatingWebFluxConfiguration, could not be registered. A bean with that name has already been defined in class path resource [com/github/tt4g/spring/webflux/error/handler/example/WebConfig.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
I understand that setting spring.main.allow-bean-definition-overriding=true according to the error messages will work, but this method causes a lot of unintentional overwriting of @Bean.
I investigated how to register a LocaleContextResolver without setting the spring.main.allow-bean-definition-overriding=true.
LocaleContextResolver is provided by EnableWebFluxConfiguration which is inner class org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration which is implemented org.springframework.web.reactive.config.WebFluxConfigurationSupport.
I can override the LocaleContextResolver by configuring a subclass of WebFluxConfigurationSupport and adding it to @Bean but I lost a lot of WebFlux auto-configuration.
Because WebFluxAutoConfiguration is annotated @ConditionalOnClass(WebFluxConfigurer.class).
Is it possible to override the LocaleContextResolver with WebFluxAutoConfiguration enabled?