spring+hibernate访问多个数据库的配置问题,为什么程序总是默认只访问其中一个数据库?
一共有两个applicationContext.xml,分别配置了两个dataSource和两个sessionFactory,但程序总是默认访问其中一个数据源。一旦访问的数据在另一个得不到的数据源时,将导致找不到表或Hibernate映射的错误。。。
配置分别如下:
applicationContext-1.xml -->
<bean id="dataSource_1"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
... ...
</bean>
<bean id="sessionFactory_1"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource_1"/>
</property>
<property name="mappingResources">
<list>
<value>...</value>
<value>...</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
**************************************************************************************
applicationContext-2.xml -->
<bean id="dataSource_2"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
... ...
</bean>
<bean id="sessionFactory_2"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource_2"/>
</property>
<property name="mappingResources">
<list>
<value>...</value>
<value>...</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>