<?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:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
">
	
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName" value="${jdbc.driverClassName}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
	</bean>
	<bean id="dataSource2" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName" value="${ho.jdbc.driverClassName}" />
		<property name="url" value="${ho.jdbc.url}" />
		<property name="username" value="${ho.jdbc.username}" />
		<property name="password" value="${ho.jdbc.password}" />
	</bean>
	<bean id="dataSource3" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName" value="${lj.jdbc.driverClassName}" />
		<property name="url" value="${lj.jdbc.url}" />
		<property name="username" value="${lj.jdbc.username}" />
		<property name="password" value="${lj.jdbc.password}" />
	</bean>
	<!-- 分页配置 -->
	<bean id="pagingPlugin" class="com.fuxi.ws.system.plugin.PagingPlugin">
		<property name="properties">
			<props>
				<prop key="dialect">com.fuxi.ws.system.plugin.PagingMSSQLDialect</prop>
				<prop key="pageSqlId">.*get.*,.*select.*</prop>
			</props>
		</property>
	</bean>
	<bean id="multipleDataSource" class="com.fuxi.ws.base.MultipleDataSource">
		<property name="defaultTargetDataSource" ref="dataSource" />
		<property name="targetDataSources">
			<map>
				<entry key="dataSource" value-ref="dataSource" />
				<entry key="dataSource2" value-ref="dataSource2" />
				<entry key="dataSource3" value-ref="dataSource3" />
			</map>
		</property>
	</bean>
	<!-- myBatis文件 -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="multipleDataSource" />
		<!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
		<property name="mapperLocations" value="classpath:com/fuxi/ws/data/mapper/*.xml" />
		<property name="plugins">
			<array>
				<ref bean="pagingPlugin" />
			</array>
		</property>
		<property name="configurationProperties">
			<props>
				<prop key="cacheEnabled">true</prop>
				<!-- 查询时，关闭关联对象即时加载以提高性能 -->
				<prop key="lazyLoadingEnabled">true</prop>
				<!-- 设置关联对象加载的形态，此处为按需加载字段(加载字段由SQL指 定)，不会加载关联表的所有字段，以提高性能 -->
				<prop key="aggressiveLazyLoading">false</prop>
				<!-- 对于未知的SQL查询，允许返回不同的结果集以达到通用的效果 -->
				<prop key="multipleResultSetsEnabled">true</prop>
				<!-- 允许使用列标签代替列名 -->
				<prop key="useColumnLabel">true</prop>
				<!-- 允许使用自定义的主键值(比如由程序生成的UUID 32位编码作为键值)，数据表的PK生成策略将被覆盖 -->
				<prop key="useGeneratedKeys">true</prop>
				<!-- 给予被嵌套的resultMap以字段-属性的映射支持 -->
				<prop key="autoMappingBehavior">FULL</prop>
				<!-- 对于批量更新操作缓存SQL以提高性能 -->
				<prop key="defaultExecutorType">BATCH</prop>
				<!-- 数据库超过25000秒仍未响应则超时 -->
				<prop key="defaultStatementTimeout">25000</prop>

			</props>
		</property>
	</bean>

	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.fuxi.ws.data.dao" />
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
	</bean>

	<!-- 配置事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="multipleDataSource" />
	</bean>
	<!-- enable transaction annotation support -->
	<tx:annotation-driven transaction-manager="transactionManager" />

	<tx:advice id="txAdvice">
		<tx:attributes>
			<tx:method name="update*" no-rollback-for="IOException" />
			<tx:method name="*" />
		</tx:attributes>
	</tx:advice>

</beans>