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

    <tx:annotation-driven/>

    <!--<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource">
        <property name="driverClassName" value="${jdbc.driver}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        &lt;!&ndash; 队列中的最大等待数 &ndash;&gt;
        <property name="idleTimeout" value="${jdbc.idleTimeout}"/>
        &lt;!&ndash; the maximum lifetime of a connection in the pool &ndash;&gt;
        &lt;!&ndash; We strongly recommend setting this value,
         and it should be at least 30 seconds less than any database-level connection timeout. &ndash;&gt;
        <property name="maxLifetime" value="${jdbc.maxLifetime}"/>
        &lt;!&ndash; 最长等待时间，单位毫秒 &ndash;&gt;
        <property name="connectionTimeout" value="${jdbc.connectionTimeout}"/>
        &lt;!&ndash; 最大连接数 &ndash;&gt;
        <property name="maximumPoolSize" value="${jdbc.maximumPoolSize}"/>
        &lt;!&ndash; controls the maximum amount of time that a connection will be tested for aliveness.
        This value must be less than the connectionTimeout &ndash;&gt;
        <property name="validationTimeout" value="${jdbc.validationTimeout}"/>
        &lt;!&ndash; CAREFUL! THIS CONFIG IMPACTS SQL PERFORMANCE A LOT! &ndash;&gt;
        &lt;!&ndash;<property name="transactionIsolation" value="TRANSACTION_REPEATABLE_READ"/>&ndash;&gt;
    </bean>-->

    <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}"/>
        <property name="initialSize" value="${jdbc.initialSize}"/>
        <property name="maxActive" value="${jdbc.maxActive}"/>
        <property name="proxyFilters">
            <list>
                <ref bean="stat-filter"/>
                <ref bean="wall-filter"/>
            </list>
        </property>
        <!--&lt;!&ndash; 配置间隔多久才进行一次检测，检测需要关闭的空闲连接，单位是毫秒 &ndash;&gt;-->
        <property name="timeBetweenEvictionRunsMillis" value="60000" />
        <!-- 配置一个连接在池中最小生存的时间，单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="300000" />
        <!-- 建议配置为true，不影响性能，并且保证安全性。申请连接的时候检测，如果空闲时间大于timeBetweenEvictionRunsMillis，执行validationQuery检测连接是否有效 -->
        <property name="testWhileIdle" value="true" />
        <!-- 指定每个连接上PSCache的大小   -->
        <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
    </bean>

    <!-- 慢sql日志 -->
    <bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter">
        <property name="slowSqlMillis" value="1000"/>
        <property name="logSlowSql" value="true"/>
        <property name="mergeSql" value="true"/>
    </bean>

    <bean id="wall-filter" class="com.alibaba.druid.wall.WallFilter">
        <property name="dbType" value="mysql"/>
        <property name="config" ref="wall-filter-config"/>
    </bean>

    <bean id="wall-filter-config" class="com.alibaba.druid.wall.WallConfig">
        <property name="multiStatementAllow" value="true"/>
    </bean>

    <bean id="druid-stat-interceptor" class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor"></bean>
    <bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut" scope="prototype">
        <property name="patterns">
            <list>
                <value>com.kmall.admin.controller.*</value>
                <value>com.kmall.admin.service.*</value>
                <value>com.kmall.api.controller.*</value>
                <value>com.kmall.api.service.*</value>
                <value>com.kmall.admin.fromcomm.controller.*</value>
                <value>com.kmall.admin.fromcomm.service.*</value>
                <value>com.kmall.gen.controller.*</value>
                <value>com.kmall.gen.service.*</value>
                <value>com.kmall.schedule.controller.*</value>
                <value>com.kmall.schedule.service.*</value>
            </list>
        </property>
    </bean>
    <aop:config>
        <aop:advisor advice-ref="druid-stat-interceptor" pointcut-ref="druid-stat-pointcut"/>
    </aop:config>

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

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource">
            <ref bean="dataSource"/>
        </property>
    </bean>

    <!-- JDBC配置 -->
    <bean id="namedParameterJdbcTemplate"
          class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
        <constructor-arg ref="dataSource"/>
    </bean>

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

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.kmall.manager.dao, com.kmall.schedule.dao, com.kmall.admin.dao, com.kmall.admin.fromcomm.dao, com.kmall.gen.dao, com.kmall.api.dao"/>
    </bean>
</beans>