<?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:mvc="http://www.springframework.org/schema/mvc"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
						http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
						http://www.springframework.org/schema/context 
						http://www.springframework.org/schema/context/spring-context-3.2.xsd
						http://www.springframework.org/schema/mvc
						http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
						http://www.springframework.org/schema/aop 
						http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">


	<!-- 
	通常来说，只需要修改initialSize、minIdle、maxActive。
	如果用Oracle，则把poolPreparedStatements配置为true，
	mysql可以配置为false。分库分表较多的数据库，建议配置为false。
	 -->
	<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> 
      <!-- 基本属性 url、user、password -->
      <property name="url" value="${jdbc.jdbcUrl}" />
      <property name="username" value="${jdbc.user}" />
      <property name="password" value="${jdbc.password}" />
      <!-- 配置初始化大小、最小、最大 -->
      <property name="initialSize" value="${jdbc.initialPoolSize}" />
      <property name="minIdle" value="${jdbc.miniPoolSize}" /> 
      <property name="maxActive" value="${jdbc.maxPoolSize}" />
      <!-- 配置获取连接等待超时的时间 -->
      <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 -->
      <property name="filters" value="stat" /> 
  </bean>

	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation">
			<value>classpath:mybatis/mybatisConfig.xml</value>
		</property>
		<property name="mapperLocations">
			<list>
				<value>classpath:durcframework_mybatis/expressionBlock.xml</value>
				<value>classpath:mybatis/mapper/*.xml</value>
			</list>
		</property>
	</bean>
	
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
        <property name="dataSource" ref="dataSource"/>  
    </bean>  
      
     <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">  
        <property name="transactionManager" ref="transactionManager"/>  
    </bean>  

	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
		<property name="basePackage" value="org.durcframework.autocode.dao" />
	</bean>
	
	
	<!-- 事务配置 -->
	<!-- 打开注释开启声明式事务,并不是所有方法都需要事务,具体要看项目需求以及团队规范
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="save*" propagation="REQUIRED"/>
		    <tx:method name="del*" propagation="REQUIRED"/>
		    <tx:method name="update*" propagation="REQUIRED"/>
		    <tx:method name="add*" propagation="REQUIRED"/>
		    <tx:method name="query*" propagation="REQUIRED" read-only="true"/>
		    <tx:method name="*Tran" propagation="REQUIRED"/>
		</tx:attributes>
	</tx:advice>

	<aop:config>
		<aop:pointcut id="interceptorPointCuts" expression="execution(* *..service.*.*(..))" />
		<aop:advisor advice-ref="txAdvice" pointcut-ref="interceptorPointCuts" />
	</aop:config>
	-->

</beans>
