<?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:task="http://www.springframework.org/schema/task"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">
    <description>Spring公共配置</description>
    <!-- 使用spring自带的占位符替换功能 -->
    <bean id="encryptPropertyPlaceholderConfigurer" class="com.njcn.utils.EncryptPropertyPlaceholderConfigurer">
        <!-- 允许JVM参数覆盖 -->
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
        <!-- 忽略没有找到的资源文件 -->
        <property name="ignoreResourceNotFound" value="true"/>
        <!-- 配置资源文件 -->
        <property name="locations">
            <list>
                <value>classpath:jdbc.properties</value>
                <value>classpath:java.properties</value>
            </list>
        </property>
    </bean>
    <!--spring自带的定时任务方案解决需要配置的 -->
    <task:annotation-driven/>
    <!-- 数据源配置,使用应用内的DBCP数据库连接池 ****start**** -->
    <bean id="MariaDB" class="com.alibaba.druid.pool.DruidDataSource"
          init-method="init" destroy-method="close" lazy-init="true">
        <property name="driverClassName" value="${mariadb.driverClass}"/>
        <property name="url" value="${mariadb.jdbcUrl}"/>
        <property name="username" value="${mariadb.user}"/>
        <property name="password" value="${mariadb.password}"/>
        <!-- 配置初始化大小、最小、最大 -->
        <property name="initialSize" value="${mariadb.initialSize}"/>
        <property name="minIdle" value="${mariadb.minIdle}"/>
        <property name="maxActive" value="${mariadb.maxActive}"/>
        <!-- 配置获取连接等待超时的时间 -->
        <property name="maxWait" value="${mariadb.maxWait}"/>
        <!-- 配置间隔多久才进行一次检测，检测需要关闭的空闲连接，单位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis" value="${mariadb.timeBetweenEvictionRunsMillis}"/>
        <!-- 配置一个连接在池中最小生存的时间，单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="${mariadb.minEvictableIdleTimeMillis}"/>
        <property name="testWhileIdle" value="true"/>
        <property name="validationQuery" value="SELECT 'x' from dual"/>
        <property name="testOnBorrow" value="false"/>
        <property name="testOnReturn" value="false"/>
        <property name="removeAbandoned" value="false"/>
        <property name="removeAbandonedTimeout" value="300"/>
        <property name="logAbandoned" value="false"/>
        <!-- 打开PSCache，并且指定每个连接上PSCache的大小 -->
        <property name="poolPreparedStatements" value="${mariadb.poolPreparedStatements}"/>
        <property name="maxPoolPreparedStatementPerConnectionSize"
                  value="${mariadb.maxPoolPreparedStatementPerConnectionSize}"/>
        <!-- 配置监控统计拦截的filters -->
        <property name="filters" value="stat"/>
    </bean>

    <bean id="Oracle" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"
          lazy-init="true">
        <property name="driverClassName" value="${oracle.driverClass}"/>
        <property name="url" value="${oracle.jdbcUrl}"/>
        <property name="username" value="${oracle.user}"/>
        <property name="password" value="${oracle.password}"/>
        <!-- 配置初始化大小、最小、最大 -->
        <property name="initialSize" value="${oracle.initialSize}"/>
        <property name="minIdle" value="${oracle.minIdle}"/>
        <property name="maxActive" value="${oracle.maxActive}"/>
        <!-- 配置获取连接等待超时的时间 -->
        <property name="maxWait" value="${oracle.maxWait}"/>
        <!-- 配置间隔多久才进行一次检测，检测需要关闭的空闲连接，单位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis" value="${oracle.timeBetweenEvictionRunsMillis}"/>
        <!-- 配置一个连接在池中最小生存的时间，单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="${oracle.minEvictableIdleTimeMillis}"/>
        <property name="testWhileIdle" value="true"/>
        <property name="validationQuery" value="SELECT 'x' from dual"/>
        <property name="testOnBorrow" value="false"/>
        <property name="testOnReturn" value="false"/>
        <property name="removeAbandoned" value="false"/>
        <property name="removeAbandonedTimeout" value="300"/>
        <property name="logAbandoned" value="false"/>
        <!-- 打开PSCache，并且指定每个连接上PSCache的大小 -->
        <property name="poolPreparedStatements" value="${oracle.poolPreparedStatements}"/>
        <property name="maxPoolPreparedStatementPerConnectionSize"
                  value="${oracle.maxPoolPreparedStatementPerConnectionSize}"/>
        <!-- 配置监控统计拦截的filters -->
        <property name="filters" value="stat"/>
    </bean>

    <bean id="vendorProperties"
          class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="properties">
            <props>
                <prop key="Oracle">Oracle</prop>
                <prop key="MariaDB">MariaDB</prop>
            </props>
        </property>
    </bean>

    <bean id="databaseIdProvider" class="org.apache.ibatis.mapping.VendorDatabaseIdProvider">
        <property name="properties" ref="vendorProperties"/>
    </bean>

    <bean class="com.njcn.utils.SpringContextUtil"/>
    <bean id="log-filter" class="com.alibaba.druid.filter.logging.Log4jFilter">
        <property name="resultSetLogEnabled" value="false"/>
        <property name="statementExecutableSqlLogEnable" value="true"/>
    </bean>

    <bean id="multipartResolver"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="defaultEncoding" value="utf-8"/>
        <property name="maxUploadSize" value="1048576000"/>
        <property name="maxInMemorySize" value="4096"/>
        <property name="resolveLazily" value="true"/>
    </bean>
    <!-- 数据源配置,使用应用内的DBCP数据库连接池 ****end**** -->
    <!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 -->
    <context:component-scan base-package="com.njcn,com.pqs9000">
        <context:exclude-filter type="annotation"
                                expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
</beans>
