Using Spring Boot 3.1.0, I cannot create a bean named "localeResolver" with type LocalResolver. When application starts, I get the following:
The bean 'localeResolver', defined in class path resource [path/to/MyConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class] and overriding is disabled.
And I'm defining LocaleResolver bean like that:
@Configuration
@EnableConfigurationProperties({SomePropertiesClasses})
public class MyConfiguration {
private final MyClass myClass;
public MessagesConfiguration(MyClass myClass) {
this.myClass = myClass;
}
@Bean
public LocaleResolver localeResolver() {
// ...
}
}
Without setting spring.main.allow-bean-definition-overriding=true I want to define a LocaleResolver bean.
Note: I don't have @EnableWebMvc annotation in my code.
Comment From: wilkinsona
Thanks for the report. Unfortunately, I cannot reproduce the behavior that you have described. When defining a bean named localeResolver the auto-configured bean with the same name backs off:
WebMvcAutoConfiguration.EnableWebMvcConfiguration#localeResolver:
Did not match:
- @ConditionalOnMissingBean (names: localeResolver; SearchStrategy: all) found beans named localeResolver (OnBeanCondition)
If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.
Comment From: snturk
I checked my project and noticed that it was a dependency-related issue. Couldn't solve it at the moment but it was not a bug about this project.