spring 3和mybatis 3如何创建多个连接数据库。我需要同时连接MySQL和Oracle。你能帮助我吗?
问问题
1479 次
1 回答
1
每个数据库需要 1 个 SqlSessionFactory。
<bean id="db1SqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:sqlmap1.xml"/>
<property name="dataSource" ref="db1datasource"/>
</bean>
<bean id="db2SqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:sqlmap2.xml"/>
<property name="dataSource" ref="db2datasource"/>
</bean>
<bean id="db1SqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<qualifier value="db1" />
<constructor-arg index="0" ref="db1SqlSessionFactory" />
</bean>
<bean id="db2SqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<qualifier value="db2" />
<constructor-arg index="0" ref="db2SqlSessionFactory" />
</bean>
于 2012-05-04T14:40:13.783 回答