定义MessageSource bean与MessageSourceAutoConfiguration冲突

时间:2019-02-18 21:07:38

标签: spring-boot

尝试定义自己的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下注册

0 个答案:

没有答案