New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LocaleResolver (MVC) and LocaleContextResolver (WebFlux) beans will back off if a user provides a bean of the same type and a custom name but Framework will then use its own default #24209
Comments
I think we probably should. I'd even say this is a bug and should perhaps be fixed in 2.2.x |
The |
In 2.2 and 2.3 the auto-configured In 2.4.0 things are different as both the |
@wilkinsona we are having a regression related to localeResolver and i'm wondering if it's related to this ticket or an actual regression in Spring We are using mvc and we localize our ui using thymeleaf. Since updating to 2.4.1 (tested with 2.4.0 and the problem is there. but it is NOT there in 2.3.7) our application doesn't start and gives the error
The error is misleading. I was able to find the conflicting bean in I haven't been able to find official documentation to configure a localizationResolver. I just followed this article which instructs to create the bean like this @Bean
public LocaleResolver localeResolver() {
SessionLocaleResolver slr = new SessionLocaleResolver();
slr.setDefaultLocale(Locale.US);
return slr;
} But again, such a bean collides with the one in WebMvcConfigurationSupport and if renamed it is not used by this.localeResolver = context.getBean(LOCALE_RESOLVER_BEAN_NAME, LocaleResolver.class); I see that 2.3.X WebMvcConfigurationSupport doesn't create a Should I open a new ticket or am I missing something? |
@theHilikus That sounds like a bug. The Could you check that you've not got an |
ah. i did have @EnableWebMvc. Once i removed that, the problem was gone Thank you for the info @philwebb |
I'm now dealing with the same problem as @theHilikus, without using
However, I cannot override that bean without using |
@snturk have you found anything to this? |
No, unfortunately. |
@mychalvlcek @snturk In this case, Phil has already suggested what to do next:
|
dont have this annotation.. my setup is following, multi-module maven project, where multiple configuration classes implementing originally i've had direct usage of componentScan like following
once I want to remove this component scan and switch just to autoconfiguration approach (module2 has autoconfiguration), it stops to work.. so I guess it is connected to order of execution of all configurations (especially those implementing |
Yes, it sounds like your auto-configuration is ordered incorrectly. The auto-configuration that defines your custom |
While looking at #24207, I noticed that our overrides of the
localeResolver()
(MVC) andlocaleContextResolver()
(WebFlux) methods will back off if anyLocaleResolver
orLocaleContextResolver
bean is present (they're annotated with a plain@ConditionalOnMissingBean
) but Framework consumes these beans using a specific name. This means that a user may provide a custom bean with a non-standard name and our auto-configuration will back off, but Framework will then use its default rather than the user's bean. If you're trying to figure out what's happened, the condition evaluation report won't help much as it'll show that the auto-configured resolver backed off in favour of the user-provided resolver but won't explain why the user-provided resolver wasn't used.I am wondering if our auto-configured beans should only back off when a bean of the name that Framework looks for is defined:
This would make the condition evaluation report more useful as it will show that the auto-configured bean was configured as no bean with a specific name was found in the context.
The text was updated successfully, but these errors were encountered: