Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'mysqlDataSource' ..factory-bean reference points back to the same bean definition
baibai 提问于:2018-10-17
1 0

springboot多数据源出错:

MysqlDataSource.java

    /**
     * dataSource
     * @return
     */
    @Primary
    @Bean(name="mysqlDataSource")
    @Qualifier("mysqlDataSource")
    @ConfigurationProperties(prefix="spring.datasource.mysql")
    public DataSource mysqlDataSource() {
        return DataSourceBuilder.create().build();
    }

错误:

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'mysqlDataSource' defined in class path resource [com/Ds/app/conf/MysqlDataSource.class]: factory-bean reference points back to the same bean definition
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:701)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:665)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:633)
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1489)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:420)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:390)
    at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:208)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1276)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:815)
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:721)
    ... 42 more
  • 所有回答
bluesky 回答于:2018-10-22
0 0

bean名字定义重复

改为:

     /**
     * dataSource
     * @return
     */
    @Primary
    @Bean(name="mySqlDs")
    @Qualifier("mySqlDs")
    @ConfigurationProperties(prefix="spring.datasource.mysql")
    public DataSource mysqlDataSource() {
        return DataSourceBuilder.create().build();
    }
我来回答    Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'mysqlDataSource' ..factory-bean reference points back to the same bean definition