<?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.xsd
	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

	<context:property-placeholder location="classpath:config.properties"/>
	<!--统一的dataSource-->
	<bean id="dynamicDataSource" class="com.lightinit.hsdataportal.spring.DynamicDataSource" >
		<property name="targetDataSources">
			<map key-type="java.lang.String">
				<!--通过不同的key决定用哪个dataSource-->
				<entry value-ref="dataSource" key="dataSource"></entry>
				<entry value-ref="camrsDataSource" key="camrsDataSource"></entry>
			</map>
		</property>
		<!--设置默认的dataSource-->
		<property name="defaultTargetDataSource" ref="dataSource">
		</property>
	</bean>

	<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
		<property name="driverClassName" value="${jdbc.sentry.driverClassName}" />
		<property name="url" value="${jdbc.sentry.url}" />
		<property name="username" value="${jdbc.sentry.username}" />
		<property name="password" value="${jdbc.sentry.password}" />
		<property name = "filters" value = "${filters}" />
		<property name="maxWait" value="${jdbc.sentry.maxWait}" />
		<property name="maxActive" value="${jdbc.sentry.maxActive}" />
		<!-- 初始化连接数量 -->
		<property name = "initialSize" value = "${jdbc.sentry.initialSize}" />
		<!-- 最小空闲连接数 -->
		<property name = "minIdle" value = "${jdbc.sentry.minIdle}" />
		<property name = "maxOpenPreparedStatements" value ="${jdbc.sentry.maxOpenPreparedStatements}" />
		<property name = "removeAbandonedTimeout" value ="${jdbc.sentry.removeAbandonedTimeout}" />
		<property name = "logAbandoned" value = "${jdbc.sentry.logAbandoned}" />
		<property name="validationQuery" value="${validationQuery}" />
		<property name="testOnBorrow" value="${jdbc.sentry.testOnBorrow}" />
		<property name="testWhileIdle" value="${jdbc.sentry.testWhileIdle}" />
		<property name="testOnReturn" value="${jdbc.sentry.testOnReturn}" />
		<property name="timeBetweenEvictionRunsMillis" value="${jdbc.sentry.timeBetweenEvictionRunsMillis}" />
		<property name="minEvictableIdleTimeMillis" value="${jdbc.sentry.minEvictableIdleTimeMillis}" />
		<property name="removeAbandoned" value="${jdbc.sentry.removeAbandoned}" />
	</bean>

	<bean name="camrsDataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
		<property name="driverClassName" value="${jdbc.camrs.driverClassName}" />
		<property name="url" value="${jdbc.camrs.url}" />
		<property name="username" value="${jdbc.camrs.username}" />
		<property name="password" value="${jdbc.camrs.password}" />
		<property name = "filters" value = "${filters}" />
		<property name="maxWait" value="${jdbc.camrs.maxWait}" />
		<property name="maxActive" value="${jdbc.camrs.maxActive}" />
		<!-- 初始化连接数量 -->
		<property name = "initialSize" value = "${jdbc.camrs.initialSize}" />
		<!-- 最小空闲连接数 -->
		<property name = "minIdle" value = "${jdbc.camrs.minIdle}" />
		<property name = "maxOpenPreparedStatements" value ="${jdbc.camrs.maxOpenPreparedStatements}" />
		<property name = "removeAbandonedTimeout" value ="${jdbc.camrs.removeAbandonedTimeout}" />
		<property name = "logAbandoned" value = "${jdbc.camrs.logAbandoned}" />
		<property name="validationQuery" value="${validationQuery}" />
		<property name="testOnBorrow" value="${jdbc.camrs.testOnBorrow}" />
		<property name="testWhileIdle" value="${jdbc.camrs.testWhileIdle}" />
		<property name="testOnReturn" value="${jdbc.camrs.testOnReturn}" />
		<property name="timeBetweenEvictionRunsMillis" value="${jdbc.camrs.timeBetweenEvictionRunsMillis}" />
		<property name="minEvictableIdleTimeMillis" value="${jdbc.camrs.minEvictableIdleTimeMillis}" />
		<property name="removeAbandoned" value="${jdbc.camrs.removeAbandoned}" />
	</bean>
	<!-- 配置session工厂 -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="configLocation" value="classpath:mybatis-config.xml" />
		<property name="dataSource" ref="dynamicDataSource" />
		<property name="mapperLocations">
			<list>
				<value>classpath:sqlmaps/*.xml</value>
			</list>
		</property>
		<property name="typeAliasesPackage" value="com.lightinit.hsdataportal.entity"></property>
	</bean>
	<!-- 事物管理 -->
	<bean id="txManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dynamicDataSource" />
	</bean>
	<!--使用注解事务 -->
	<tx:annotation-driven  transaction-manager="txManager" />

	<!-- 扫描mybatis-generator-core.jar生成的dao层接口 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.lightinit.hsdataportal.mapper,com.lightinit.hsdataportal.*.mapper" />
		<!--<property name="markerInterface" value="org.mybatis.spring.mapper.MapperFactoryBean"></property> -->
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
	</bean>
</beans>