从数据源配置文件
原有数据源不变动下,新增配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<!-- ========================================配置数据源========================================= -->
<!-- crm数据源的配置 -->
<bean id="dataSourceCrm" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="driverClassName" value="${jdbc.crm.driver}" />
<property name="url" value="${jdbc.crm.url}" />
<property name="username" value="${jdbc.crm.username}" />
<property name="password" value="${jdbc.crm.password}" />
<property name="initialSize" value="20" />
<property name="maxActive" value="500" />
<property name="minIdle" value="3" />
<property name="removeAbandoned" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testWhileIdle" value="true" />
<property name="testOnReturn" value="false" />
<property name="removeAbandonedTimeout" value="600" />
<property name="maxWait" value="60000" />
<property name="validationQuery" value="SELECT 1" />
<property name="timeBetweenEvictionRunsMillis" value="3600000" />
<property name="minEvictableIdleTimeMillis" value="3600000" />
</bean>
<!-- ========================================针对myBatis的配置项============================== -->
<!-- 配置扫描器 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.qunji.sale.console.batch.crm" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactorytwo" />
</bean>
<!-- 配置sqlSessionFactorytwo -->
<bean id="sqlSessionFactorytwo" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:mybatis/SqlCrmMapConfig.xml" />
<property name="dataSource" ref="dataSourceCrm" />
<property name="mapperLocations" value="classpath:mapping/crm/*.xml" />
</bean>
</beans>
注意的问题
1.保证主数据源扫描的dao,和从数据源扫描的dao不能重复
2.关于事务问题要注意,最好默认主数据源,有特殊需求则修改配置