You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
wilkinsona
changed the title
Can not register custom LocaleContextResolver with WebFluxAutoConfiguration enabled
Allow users to define their own LocaleContextResolver bean when using WebFlux
Sep 22, 2020
I've used this issue to make the auto-configured LocaleContextResolver back off when one's defined in an app's configuration. I've opened #23449 to add locale and locale-resolver properties that control the locale and how it's resolved.
@tt4g No problem. I think you could work around the current limitation by changing the name of your bean to something other than localeContextResolver and marking it @Primary.
Uh oh!
There was an error while loading. Please reload this page.
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:
I get runtime error:
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 thespring.main.allow-bean-definition-overriding=true
.LocaleContextResolver
is provided byEnableWebFluxConfiguration
which is inner classorg.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration
which is implementedorg.springframework.web.reactive.config.WebFluxConfigurationSupport
.https://github.com/spring-projects/spring-framework/blob/69921b49a5836e412ffcd1ea2c7e20d41f0c0fd6/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java#L314-L324
I can override the
LocaleContextResolver
by configuring a subclass ofWebFluxConfigurationSupport
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
withWebFluxAutoConfiguration
enabled?The text was updated successfully, but these errors were encountered: