<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd">
<!-- 引入配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties,classpath*:sysConfig.properties"/>
<bean id="activity_ssf" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="ds_activity" />
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:com/url/mapping/*.xml"></property>
<!-- 指定实体类包名,根据类名自动进行mybatis类型映射 -->
<property name="typeAliasesPackage" value="com.url.pojo"></property>
</bean>
<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.url.dao" />
<property name="sqlSessionFactoryBeanName" value="test_ssf"></property>
</bean>
<!-- <aop:aspectj-autoproxy /> -->
<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="tm_sns_activity"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="ds_test" />
</bean>
<!-- 动态数据源-->
<bean id="ds_activity" class="com.test.base.DynamicDataSource">
<property name="targetDataSources">
<map key-type="java.lang.String">
<entry value-ref="ds_test" key="ds_test"></entry>
</map>
</property>
</bean>
<bean id="ds_test" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="defaultAutoCommit" value="${jdbc.defaultAutoCommit}" />
<property name="initialSize" value="${jdbc.initialSize}"></property>
<property name="maxActive" value="${jdbc.maxActive}"/>
<property name="maxIdle" value="${jdbc.maxIdle}" />
<property name="minIdle" value="${jdbc.minIdle}" />
<property name="maxWait" value="${jdbc.maxWait}" />
<property name="testOnBorrow" value="${jdbc.testOnBorrow}" />
<property name="testOnReturn" value="${jdbc.testOnReturn}" />
<property name="testWhileIdle" value="${jdbc.testWhileIdle}" />
<property name="removeAbandoned" value="${jdbc.removeAbandoned}" />
<property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}" />
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" />
<property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}" />
<property name="logAbandoned" value="${jdbc.logAbandoned}" />
<property name="connectionInitSqls" value="${connectionInitSqls}"/>
</bean>
<bean id="test1" class="com.ptest14">
<property name="str" value="test2"/>
</bean>
</beans>
spring-mvc.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd">
<!-- 引入配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties,classpath*:sysConfig.properties"/>
<bean id="activity_ssf" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="ds_activity" />
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:com/url/mapping/*.xml"></property>
<!-- 指定实体类包名,根据类名自动进行mybatis类型映射 -->
<property name="typeAliasesPackage" value="com.url.pojo"></property>
</bean>
<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.url.dao" />
<property name="sqlSessionFactoryBeanName" value="test_ssf"></property>
</bean>
<!-- <aop:aspectj-autoproxy /> -->
<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="tm_sns_activity"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="ds_test" />
</bean>
<!-- 动态数据源-->
<bean id="ds_activity" class="com.test.base.DynamicDataSource">
<property name="targetDataSources">
<map key-type="java.lang.String">
<entry value-ref="ds_test" key="ds_test"></entry>
</map>
</property>
</bean>
<bean id="ds_test" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="defaultAutoCommit" value="${jdbc.defaultAutoCommit}" />
<property name="initialSize" value="${jdbc.initialSize}"></property>
<property name="maxActive" value="${jdbc.maxActive}"/>
<property name="maxIdle" value="${jdbc.maxIdle}" />
<property name="minIdle" value="${jdbc.minIdle}" />
<property name="maxWait" value="${jdbc.maxWait}" />
<property name="testOnBorrow" value="${jdbc.testOnBorrow}" />
<property name="testOnReturn" value="${jdbc.testOnReturn}" />
<property name="testWhileIdle" value="${jdbc.testWhileIdle}" />
<property name="removeAbandoned" value="${jdbc.removeAbandoned}" />
<property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}" />
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" />
<property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}" />
<property name="logAbandoned" value="${jdbc.logAbandoned}" />
<property name="connectionInitSqls" value="${connectionInitSqls}"/>
</bean>
<bean id="test1" class="com.ptest14">
<property name="str" value="test2"/>
</bean>
</beans>