applicationContext-datasource.xml 3.43 KB
<?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:mvc="http://www.springframework.org/schema/mvc" 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.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
  <!-- DruidDataSource数据源配置) -->
  <!-- See: https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_DruidDataSource%E5%8F%82%E8%80%83%E9%85%8D%E7%BD%AE -->
  <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
                 init-method="init" destroy-method="close">
  <!-- 基本属性 url、user、password -->
  <property name="url" value="${jdbc_url}" />
  <property name="username" value="${jdbc_user}" />
  <property name="password" value="${jdbc_password}" />

  <!-- 配置初始化大小、最小、最大 -->
  <property name="initialSize" value="${atms.config.druid.initialSize:0}" />
  <property name="minIdle" value="${atms.config.druid.minIdle:1}" />
  <property name="maxActive" value="${atms.config.druid.maxActive:20}" />

  <!-- 配置获取连接等待超时的时间 -->
  <property name="maxWait" value="${atms.config.druid.maxWait:60000}" />

  <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
  <property name="timeBetweenEvictionRunsMillis" value="${atms.config.druid.timeBetweenEvictionRunsMillis:60000}" />

  <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
  <property name="minEvictableIdleTimeMillis" value="${atms.config.druid.minEvictableIdleTimeMillis:300000}" />

  <property name="validationQuery" value="${jdbc_validationQuery:SELECT 'x'" />
  <property name="testWhileIdle" value="true" />
  <property name="testOnBorrow" value="false" />
  <property name="testOnReturn" value="false" />

  <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
  <property name="poolPreparedStatements" value="true" />
  <property name="maxPoolPreparedStatementPerConnectionSize"
            value="20" />

  <!-- 配置监控统计拦截的filters -->
  <property name="filters" value="stat" />
</bean>

  <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="dataSource"/>
  </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>pwc.taxtech.atms.dao.*</value>
        <value>pwc.taxtech.atms.vatDao.*</value>
      </list>
    </property>
  </bean>

  <aop:config>
    <aop:advisor advice-ref="druid-stat-interceptor" pointcut-ref="druid-stat-pointcut"/>
  </aop:config>
</beans>