一个项目需要连两个数据库 如下配置报错
<!-- ② 定义一个数据源 -->
<bean id="dataSource1" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="url" value="jdbc:mysql://192.168.1.200/db1" />
<property name="username" value="root" />
<property name="password" value="1234" />
<property name="initialSize" value="1" />
<property name="maxActive" value="20" />
</bean>
<!-- 定义一个db_bbs数据源 -->
<bean id="dataSource2" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="url" value="jdbc:mysql://192.168.1.200/db2" />
<property name="username" value="root" />
<property name="password" value="1234" />
<property name="initialSize" value="1" />
<property name="maxActive" value="20" />
</bean>
<!-- 定义Hibernate的Session工厂 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource1" ref="dataSource1" />
<property name="dataSource2" ref="dataSource2" />
<property name="packagesToScan">
<!-- ③-1 扫描基于JPA 注解PO类目录 -->
<list>
<value>com.test.model.entity</value>
</list>
</property>
</bean>
<!-- ④ 定义HibernateTemplate -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"
p:sessionFactory-ref="sessionFactory" />
</beans>
@非技术专家群体:严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.orm.hibernate3.HibernateTemplate com.test.dao.BaseDaoImpl.hibernateTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplate' defined in class path resource [test-dao.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [test-dao.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dateSource2' of bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Bean property 'dateSource2' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。