<?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:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" 
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:cache="http://www.springframework.org/schema/cache"
	 xmlns:task="http://www.springframework.org/schema/task"
	xsi:schemaLocation="http://www.springframework.org/schema/beans  
		   http://www.springframework.org/schema/beans/spring-beans-4.3.xsd 
		   http://www.springframework.org/schema/mvc 
		   http://www.springframework.org/schema/mvc/spring-mvc.xsd	
		   http://www.springframework.org/schema/aop   
		   http://www.springframework.org/schema/aop/spring-aop-4.3.xsd  
		   http://www.springframework.org/schema/tx  
		   http://www.springframework.org/schema/tx/spring-tx-4.3.xsd  
		   http://www.springframework.org/schema/cache
		   http://www.springframework.org/schema/cache/spring-cache.xsd
		   http://www.springframework.org/schema/context  
		   http://www.springframework.org/schema/context/spring-context-4.3.xsd">
	
	<!-- 配置数据源druid -->
	<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
		<property name="url" value="${jdbc_url}"/>
		<property name="username" value="${jdbc_username}"/>
		<property name="password" value="${jdbc_password}"/>
		<!-- init params-->
		<property name="initialSize" value="1" />	  <!-- 初始化大小 -->
		<property name="minIdle" value="1" />   	   <!-- 最小-->
		<property name="maxActive" value="50" /> 	   <!-- 最大-->
		 <!-- 配置获取连接等待超时的时间 -->  
		<property name="maxWait" value="60000" />  
		<!-- 配置间隔多久才进行一次检测，检测需要关闭的空闲连接，单位是毫秒 -->  
		<property name="timeBetweenEvictionRunsMillis" value="60000" />  
		<!-- 配置一个连接在池中最小生存的时间，单位是毫秒 -->  
		<property name="minEvictableIdleTimeMillis" value="300000" />  		
		<property name="validationQuery" value="SELECT 'x'" />  
		<property name="testWhileIdle" value="true" />  
		<property name="testOnBorrow" value="false" />  
		<property name="testOnReturn" value="false" />  	   
		<!-- 打开PSCache，并且指定每个连接上PSCache的大小 -->  
		<property name="poolPreparedStatements" value="true" />  
		<property name="maxPoolPreparedStatementPerConnectionSize" value="20" />  	   
		<!-- 配置监控统计拦截的filters，去掉后监控界面sql无法统计 -->  
		<property name="filters" value="stat" /> 
	</bean>
	
	<!-- MapperScanner -->
	<!-- <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="org.fouram.*" />
	</bean> -->

	<!-- 事务处理 -->
	<tx:annotation-driven transaction-manager="transactionManager" />

	<bean name="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"></property>
	</bean>

	<!-- 配置mybatis -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation" value="classpath:spring/mybatis-config.xml"></property>
		<property name="mapperLocations" value="classpath*:**/mapper/*Mapper.xml" />
	</bean>

	<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
		<constructor-arg ref="sqlSessionFactory" />
	</bean>
</beans>