在迁移到Spring Boot 3之前,我创建了localeResolver
bean,如下所示:
@Bean
public LocaleResolver localeResolver(MessageSourceProperties properties) {
CookieLocaleResolver clr = new CookieLocaleResolver(properties.getCookieName());
clr.setDefaultLocale(Locale.ENGLISH);
return clr;
}
但是现在这个bean已经定义好了,我得到了错误:
The bean 'localeResolver', defined in class path resource [com/app/autoconfigure/internationalization/I18nAutoConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class] and overriding is disabled.
此Bean在类WebMvcConfigurationSupport
中创建。
如何覆盖它?
1条答案
按热度按时间sd2nnvve1#
有两种方法可以解决这个问题:
1.将方法名称“localeResolver”更改为其他名称;因为“Spring将带注解的方法的名称作为bean名称”。
1.设置@Bean注解的name属性。
您可以参考以下内容:https://www.baeldung.com/spring-boot-bean-definition-override-exception