<?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:context="http://www.springframework.org/schema/context"
	   xmlns:tx="http://www.springframework.org/schema/tx"
	   xmlns:p="http://www.springframework.org/schema/p"
	   xsi:schemaLocation="http://www.springframework.org/schema/beans
					http://www.springframework.org/schema/beans/spring-beans.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
					http://www.springframework.org/schema/tx
					http://www.springframework.org/schema/tx/spring-tx.xsd">
	<!-- 获取jdbc配置文件 -->
	<context:property-placeholder location="classpath:jdbc.properties"/>

	<!--app 前台配置库数据源-->
	<bean id="ratfwDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
		<!-- 数据源驱动类可不写，Druid默认会自动根据URL识别DriverClass -->
		<property name="driverClassName" value="${jdbc.driver}" />
		<!-- 基本属性 url、user、password -->
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		<!-- 配置初始化大小、最小、最大 -->
		<property name="initialSize" value="${jdbc.pool.init}" />
		<property name="minIdle" value="${jdbc.pool.minIdle}" />
		<property name="maxActive" value="${jdbc.pool.maxActive}" />
		<!-- 配置获取连接等待超时的时间 -->
		<property name="maxWait" value="60000" />
		<!-- 配置间隔多久才进行一次检测，检测需要关闭的空闲连接，单位是毫秒 -->
		<property name="timeBetweenEvictionRunsMillis" value="60000" />
		<!-- 配置一个连接在池中最小生存的时间，单位是毫秒 -->
		<property name="minEvictableIdleTimeMillis" value="300000" />
		<property name="validationQuery" value="${jdbc.testSql}" />
		<property name="testWhileIdle" value="true" />
		<property name="testOnBorrow" value="false" />
		<property name="testOnReturn" value="false" />
		<property name="filters" value="stat"/>
		<!-- 配置监控统计拦截的filters -->
		<property name="proxyFilters">
			<list>
				<ref bean="wall-filter"/>
			</list>
		</property>
	</bean>
	<bean id="wall-filter" class="com.alibaba.druid.wall.WallFilter">
		<property name="config" ref="wall-config" />
	</bean>
	<bean id="wall-config" class="com.alibaba.druid.wall.WallConfig">
		<property name="multiStatementAllow" value="true" />
	</bean>

	<!-- 配置SqlSessionFactoryBean -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<!-- 配置数据源 -->
		<property name="dataSource" ref="ratfwDataSource" />
		<property name="configLocation" value="classpath:iamberry-wechat-service-mybatis.xml" />
	</bean>

	<!-- 自动扫描SQL隐射文件 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<!-- basePackage:指定SQL映射文件、接口的包，自动加载SQL映射文件和接口 -->
		<property name="basePackage"  value="com.iamberry.**.service.**.mapper" />
		<!-- 引用SQLSessionFactoryBean -->
		<property name="sqlSessionFactoryBeanName"  value="sqlSessionFactory" />
	</bean>

	<!-- 事物管理 -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="ratfwDataSource" />
	</bean>

	<tx:advice id="webTxAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<!-- 需要多个service协同操作，并需要事务支持的均以doxxx开头-->
			<tx:method name="do*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
			<tx:method name="delete*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
			<tx:method name="insert*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" />
			<tx:method name="update*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" />
			<tx:method name="synUpdate*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" />
			<tx:method name="save*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" />
			<!-- 凡是查询，都不开协同操作 -->
			<tx:method name="get*" read-only="true" propagation="SUPPORTS"/>
			<tx:method name="find*" read-only="true" propagation="SUPPORTS"/>
			<tx:method name="query*" read-only="true" propagation="SUPPORTS"/>
			<tx:method name="is*" read-only="true" propagation="SUPPORTS"/>
			<tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
		</tx:attributes>
	</tx:advice>
	<!-- 事务处理 -->
	
	<!-- 事物切入点 -->
	<aop:config>
		<aop:pointcut expression="execution(* com.iamberry.wechat.service.*.*.*(..))" id="userPoint" />
		<aop:advisor advice-ref="webTxAdvice" pointcut-ref="userPoint" />
	</aop:config>
</beans>