尝试定义自己的MessageSource @Bean时出现异常
The bean 'messageSource', defined in class path resource [org/maneo/services/ServicesAutoConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/context/MessageSourceAutoConfiguration.class] and overriding is disabled.
我的@Bean
是在@Configuration
类中定义的,该类本身已注册用于自动配置。
@Bean(name = "messageSource")
public MessageSource configureMessageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasenames("classpath:messages", "classpath:services.messages");
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}
更新
我只使用@Configuration
文件,没有XML配置。上面的Bean是在@Configuration
类中定义的,该类已在我的spring.factories库中的EnableAutoConfiguration下注册