java - spring配置多个数据源bug
高洛峰
高洛峰 2017-04-18 10:00:28
[Java讨论组]

<bean id="dataSource" class="com.wacai.datamigration.configs.DynamicDataSource">

    <property name="targetDataSources">
        <!-- 制定lookupKey和与之对应的数据源 -->
        <map key-type="java.lang.String">
            <entry key="donghuaDataSource" value-ref="donghuaDataSource"/>
            <entry key="adanosDataSource" value-ref="adanosDataSource"/>
        </map>
    </property>
    <!-- 指定默认数据源 -->
    <property name="defaultTargetDataSource" ref="donghuaDataSource"/>
</bean>

报错如下:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'taskController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.wacai.datamigration.services.BusinessControlManager com.wacai.datamigration.controllers.TaskController.businessControlManager; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'businessControlManager': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.wacai.datamigration.services.DataServiceDispatch com.wacai.datamigration.services.BusinessControlManager.dataServiceDispatch; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataServiceDispatch' defined in file [E:wacaiworkspaceData-Migrationtargetclassesspringbean-spring.xml]: Cannot create inner bean 'com.wacai.datamigration.services.test.TestService#2024293c' of type [com.wacai.datamigration.services.test.TestService] while setting bean property 'dataServiceMap' with key [TypedStringValue: value [test], target type [null]]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.wacai.datamigration.services.test.TestService#2024293c': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.wacai.datamigration.dao.test.TestDao com.wacai.datamigration.services.test.TestService.testDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.wacai.datamigration.mapper.test.TestsMapper com.wacai.datamigration.dao.test.TestDao.testsMapper; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testsMapper' defined in file [E:wacaiworkspaceData-MigrationtargetclassescomwacaidatamigrationmappertestTestsMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory': : Error creating bean with name 'sqlSessionFactory' defined in file [E:wacaiworkspaceData-Migrationtargetclassesspringdatabase.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in file [E:wacaiworkspaceData-Migrationtargetclassesspringdatabase.xml]: Cannot resolve reference to bean 'donghuaDataSource' while setting bean property 'targetDataSources' with key [TypedStringValue: value [donghuaDataSource], target type [class java.lang.String]]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'donghuaDataSource' defined in file [E:wacaiworkspaceData-Migrationtargetclassesspringdatabase.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to decrypt.; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in file [E:wacaiworkspaceData-Migrationtargetclassesspringdatabase.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in file [E:wacaiworkspaceData-Migrationtargetclassesspringdatabase.xml]: Cannot resolve reference to bean 'donghuaDataSource' while setting bean property 'targetDataSources' with key [TypedStringValue: value [donghuaDataSource], target type [class java.lang.String]]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'donghuaDataSource' defined in file [E:wacaiworkspaceData-Migrationtargetclassesspringdatabase.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to decrypt.

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(1)
PHP中文网

你所展示的这个XML片段没有问题,看起来你的问题好像是value-ref="donghuaDataSource",建议把配置文件补全。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号