具体原因
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.wk.itknowledage.article.AppArticle]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name ‘mySQLConfig’ for bean class [com.wk.itknowledage.common.mysql.MySQLConfig] conflicts with existing, non-compatible bean definition of same name and class [com.wk.itknowledage.article.config.MySQLConfig]

这种情况一般是容器中导入了两个命名相同的bean,我们知道标注了@Component,@Service,@Controller等注解的类会创建对象,但前提是可以扫描的到这些类。

如图:

org.springframework.beans.factory.BeanDefinitionStoreException:xxx conflicts with existing
org.springframework.beans.factory.BeanDefinitionStoreException:xxx conflicts with existing

org.springframework.beans.factory.BeanDefinitionStoreException:xxx conflicts with existing
article工程引入了common工程,需要common工程的数据源配置,那么这时候就需要在article工程写一个配置类,让其扫描common工程下的MySQLConfig,但由于这两个工程的文件名都为MySQLConfig,所以就会创建两个对象,这样就造成了冲突。

解决

  • 给bean起一个别名
    org.springframework.beans.factory.BeanDefinitionStoreException:xxx conflicts with existing
  • 修改文件名
    org.springframework.beans.factory.BeanDefinitionStoreException:xxx conflicts with existing

相关文章: