<?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"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       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 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <context:component-scan base-package="com.kmall.framework.dao,com.kmall.framework.service">
        <!--过滤定时任务service-->
        <context:exclude-filter type="regex" expression="com.kmall.framework.service.impl.ScheduleJobServiceImpl"/>
    </context:component-scan>

    <bean id="placeholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:conf/db.properties</value>
                <value>classpath:conf/express-kdn.properties</value>
                <value>classpath:conf/redis.properties</value>
                <value>classpath:conf/cus.properties</value>
                <value>classpath:conf/servlet.properties</value>
                <value>classpath:conf/wx-mp.properties</value>
                <value>classpath:conf/wx-global.properties</value>
                <value>classpath:conf/pingan-pay.properties</value>
                <value>classpath:conf/oms-merch.properties</value>
                <value>classpath:conf/websocket.properties</value>
                <value>classpath:conf/print-ticket.properties</value>
                <value>classpath:conf/common.properties</value>
                <value>classpath:conf/fastdfs.properties</value>
            </list>
        </property>
        <property name="fileEncoding" value="UTF-8"/>
    </bean>
    <context:annotation-config/>
    <mvc:default-servlet-handler/>
    <aop:aspectj-autoproxy proxy-target-class="true"/>
    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/html;charset=UTF-8</value>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
                <property name="features">
                    <list>
                        <value>WriteMapNullValue</value>
                        <value>QuoteFieldNames</value>
                        <value>WriteDateUseDateFormat</value>
                        <!-- 禁用fastjson循环引用检测 -->
                        <value>DisableCircularReferenceDetect</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

    <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}</value>
        </property>
        <property name="username">
            <value>${jdbc.username}</value>
        </property>
        <property name="password">
            <value>${jdbc.password}</value>
        </property>
        <property name="initialSize">
            <value>${jdbc.initialSize}</value>
        </property>
        <property name="maxActive">
            <value>${jdbc.maxActive}</value>
        </property>
        <property name="proxyFilters">
            <list>
                <ref bean="stat-filter"/>
                <!--过滤永真条件 防止注入-->
                <ref bean="wall-filter"/>
            </list>
        </property>
        <property name="connectionInitSqls" value="set names utf8mb4;"/>
        <!--&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>

    <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.framework.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.framework.dao"/>
    </bean>

    <bean id="restTemplate" class="org.springframework.web.client.RestTemplate"/>
</beans>
