<?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" />
		<!-- 物理连接初始化的时候执行的sql ： 设置编码，Mysql服务器需要更高版本 -->
		<property name="connectionInitSqls" value="set names utf8mb4;"/>
        <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:orm.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:annotation-driven transaction-manager="transactionManager"/>

</beans>