每个MapperScannerConfigurer配置添加属性节点
<property name="sqlSessionFactory" ref="SqlSessionFactory01"></property>
,ref引入相应的会话工厂bean。
<!--01 oracle database config--> <bean id="DataSource01" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:..." /> <property name="username" value="user1" /> <property name="password" value="111111" /> <property name="initialSize" value="2" /> <property name="minIdle" value="2" /> <property name="maxActive" value="20" /> <property name="maxIdle" value="20" /> </bean> <bean id="SqlSessionFactory01" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="DataSource01" /> <property name="configLocation" value="classpath:mybatis-config01.xml" /> </bean> <bean name="MapperScanner01" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.***.oracle.mybatis" /> <property name="sqlSessionFactory" ref="SqlSessionFactory01"></property> </bean> <!--02 mysql database config--> <bean id="SQLDataSource02" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql:..." /> <property name="username" value="user2" /> <property name="password" value="111111" /> <property name="initialSize" value="2" /> <property name="minIdle" value="2" /> <property name="maxActive" value="20" /> <property name="maxIdle" value="20" /> </bean> <bean id="SqlSessionFactory02" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="SQLDataSource02" /> <property name="configLocation" value="classpath:mybatis-config02.xml" /> </bean> <bean name="MapperScanner01" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.***.mysql.mybatis" /> <property name="sqlSessionFactory" ref="SqlSessionFactory02"></property> </bean>