applicationContext.xml
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">
<context:component-scan base-package="com.xxx" />
<context:component-scan base-package="com.xxx" />
<context:component-scan base-package="com.xxx" />
<!--数据源1-->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
destroy-method="close">
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="driverClassName" value="${jdbc.driver}" />
<property name="maxActive" value="10" />
<property name="minIdle" value="5" />
</bean>
<!--数据源2)-->
<bean id="affairsDataSource" class="com.alibaba.druid.pool.DruidDataSource"
destroy-method="close">
<property name="driverClassName" value="${affairs.jdbc.driver}" />
<property name="url" value="${affairs.jdbc.url}" />
<property name="username" value="${affairs.jdbc.username}" />
<property name="password" value="${affairs.jdbc.password}" />
<property name="maxActive" value="10" />
<property name="minIdle" value="5" />
</bean>
<!--1-3:多数据源(整合)-->
<bean id="multiDataSource" class="com.xxx.config.MultiDataSource">
<!--设置:默认数据源为(系统原始数据源)-->
<property name="defaultTargetDataSource" ref="dataSource"/>
<!--配置:数据源2为备选。-->
<property name="targetDataSources">
<map>
<entry key="affairsDataSource" value-ref="affairsDataSource"/>
</map>
</property>
</bean>