每一数据库都需要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>