druid-1.1.1.jarcss
dbconfig.propertiesjava
url:zeroDateTimeBehavior=convertToNull&rewriteBatchedStatements=true&autoReconnect=true&failOverReadOnly=false&useSSL=false driverClassName:com.mysql.jdbc.Driver username:ro password:VAxbiQ filters:stat,wall,log4j urltem:jdbc:db2:/ driverClassNametem:com.ibm.db2.jcc.DB2Driver usernameterm: passwordtem: initialSize:1 maxActive:50 minIdle:10 maxWait:60000 timeBetweenEvictionRunsMillis:60000 minEvictableIdleTimeMillis:300000 validationQuery:SELECT 'x' validationQuerytem:select 1 from sysibm.sysdummy1 testWhileIdle:true testOnBorrow:false testOnReturn:false maxOpenPreparedStatements:20 removeAbandoned:true removeAbandonedTimeout:1800 logAbandoned:true
web.xmlmysql
<!-- 鏈接池 啓用Web監控統計功能 start--> <filter> <filter-name>DruidWebStatFilter</filter-name> <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class> <init-param> <param-name>exclusions</param-name> <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value> </init-param> <init-param> <param-name>principalSessionName</param-name> <param-value>userCode</param-value> </init-param> <init-param> <param-name>profileEnable</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>DruidWebStatFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>DruidStatView</servlet-name> <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class> <init-param> <!-- 容許清空統計數據 --> <param-name>resetEnable</param-name> <param-value>true</param-value> </init-param> <init-param> <!-- 用戶名 --> <param-name>loginUsername</param-name> <param-value>admin</param-value> </init-param> <init-param> <!-- 密碼 --> <param-name>loginPassword</param-name> <param-value>sj111</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>DruidStatView</servlet-name> <url-pattern>/druid/*</url-pattern> </servlet-mapping> <!-- 鏈接池 啓用Web監控統計功能 end-->
applicationContext.xmlweb
<?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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- 採用註釋的方式配置bean --> <context:annotation-config /> <!-- 配置要掃描的包 --> <context:component-scan base-package="com.icss.ah"></context:component-scan> <!--proxy-target-class="true"強制使用cglib代理 若是爲false則spring會自動選擇--> <aop:aspectj-autoproxy proxy-target-class="true"/> <!-- 配置數據源 --> <!-- <bean id="dataSource_wx" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" > <value>java:comp/env/jdbc/wx</value> </property> </bean> --> <bean id="sqlSessionFactory_wx" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource_wx" /> <property name="databaseIdProvider" ref="databaseIdProvider"/> <property name="configLocation" value="classpath:mybatis-config.xml"/> </bean> <!-- 配置SqlSessionTemplate --> <bean id="sqlSessionTemplate_wx" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory_wx" /> </bean> <!-- 第二個數據源 --> <!-- <bean id="dataSource_temp" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" > <value>java:comp/env/jdbc/etmp</value> </property> </bean> --> <bean id="sqlSessionFactory_temp" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource_temp" /> <property name="databaseIdProvider" ref="databaseIdProvider"/> <property name="configLocation" value="classpath:mybatis-configdb2.xml"/> </bean> <!-- 配置SqlSessionTemplate --> <bean id="sqlSessionTemplate_temp" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory_temp" /> </bean> <!-- 阿里druid數據庫鏈接池 --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:dbconfig.properties</value> </list> </property> </bean> <bean id="dataSource_wx" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"> <!-- 數據庫基本信息配置 --> <property name="url" value="${url}" /> <property name="username" value="${username}" /> <property name="password" value="${password}" /> <property name="driverClassName" value="${driverClassName}" /> <property name="filters" value="${filters}" /> <property name="initialSize" value="${initialSize}" /><!-- 初始化鏈接數量 --> <property name="maxActive" value="${maxActive}" /><!-- 最大併發鏈接數 --> <property name="minIdle" value="${minIdle}" /><!-- 最小鏈接池數量 --> <property name="maxWait" value="${maxWait}" /><!-- 配置獲取鏈接等待超時的時間 --> <property name="timeBetweenEvictionRunsMillis" value="${timeBetweenEvictionRunsMillis}" /><!-- Destroy線程會檢測鏈接的間隔時間,若是鏈接空閒時間大於等於minEvictableIdleTimeMillis則關閉物理鏈接,testWhileIdle的判斷依據 --> <property name="minEvictableIdleTimeMillis" value="${minEvictableIdleTimeMillis}" /><!-- 鏈接保持空閒而不被驅逐的最長時間 --> <property name="validationQuery" value="${validationQuery}" /><!-- 用來檢測鏈接是否有效的sql,要求是一個查詢語句,經常使用select 'x' --> <property name="testWhileIdle" value="${testWhileIdle}" /><!-- 建議配置爲true,不影響性能,而且保證安全性。申請鏈接的時候檢測,若是空閒時間大於timeBetweenEvictionRunsMillis,執行validationQuery檢測鏈接是否有效 --> <property name="testOnBorrow" value="${testOnBorrow}" /><!-- 申請鏈接時執行validationQuery檢測鏈接是否有效,作了這個配置會下降性能 --> <property name="testOnReturn" value="${testOnReturn}" /><!-- 歸還鏈接時執行validationQuery檢測鏈接是否有效,作了這個配置會下降性能。 --> <property name="maxOpenPreparedStatements" value="${maxOpenPreparedStatements}" /><!-- 鏈接保持空閒而不被驅逐的最長時間 --> <property name="removeAbandoned" value="${removeAbandoned}" /><!-- 是否打開removeAbandoned功能,排查程序中是否有鏈接未關閉用,平時關閉 --> <property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}" /><!-- 1800秒,也就是30分鐘 --> <property name="logAbandoned" value="${logAbandoned}" /><!-- 關閉abanded鏈接時輸出錯誤日誌 --> </bean> <bean id="dataSource_temp" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"> <!-- 數據庫基本信息配置 --> <property name="url" value="${urltem}" /> <property name="username" value="${usernameterm}" /> <property name="password" value="${passwordtem}" /> <property name="driverClassName" value="${driverClassNametem}" /> <property name="filters" value="${filters}" /> <property name="initialSize" value="${initialSize}" /><!-- 初始化鏈接數量 --> <property name="maxActive" value="${maxActive}" /><!-- 最大併發鏈接數 --> <property name="minIdle" value="${minIdle}" /><!-- 最小鏈接池數量 --> <property name="maxWait" value="${maxWait}" /><!-- 配置獲取鏈接等待超時的時間 --> <property name="timeBetweenEvictionRunsMillis" value="${timeBetweenEvictionRunsMillis}" /><!-- Destroy線程會檢測鏈接的間隔時間,若是鏈接空閒時間大於等於minEvictableIdleTimeMillis則關閉物理鏈接,testWhileIdle的判斷依據 --> <property name="minEvictableIdleTimeMillis" value="${minEvictableIdleTimeMillis}" /><!-- 鏈接保持空閒而不被驅逐的最長時間 --> <property name="validationQuery" value="${validationQuerytem}" /><!-- 用來檢測鏈接是否有效的sql,要求是一個查詢語句,經常使用select 'x' --> <property name="testWhileIdle" value="${testWhileIdle}" /><!-- 建議配置爲true,不影響性能,而且保證安全性。申請鏈接的時候檢測,若是空閒時間大於timeBetweenEvictionRunsMillis,執行validationQuery檢測鏈接是否有效 --> <property name="testOnBorrow" value="${testOnBorrow}" /><!-- 申請鏈接時執行validationQuery檢測鏈接是否有效,作了這個配置會下降性能 --> <property name="testOnReturn" value="${testOnReturn}" /><!-- 歸還鏈接時執行validationQuery檢測鏈接是否有效,作了這個配置會下降性能。 --> <property name="maxOpenPreparedStatements" value="${maxOpenPreparedStatements}" /><!-- 鏈接保持空閒而不被驅逐的最長時間 --> <property name="removeAbandoned" value="${removeAbandoned}" /><!-- 是否打開removeAbandoned功能,排查程序中是否有鏈接未關閉用,平時關閉 --> <property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}" /><!-- 1800秒,也就是30分鐘 --> <property name="logAbandoned" value="${logAbandoned}" /><!-- 關閉abanded鏈接時輸出錯誤日誌 --> </bean> <!-- 配置支持多類型數據庫 --> <bean id="vendorProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="properties"> <props> <prop key="SQL Server">sqlserver</prop> <prop key="DB2">db2</prop> <prop key="Oracle">oracle</prop> <prop key="MySQL">mysql</prop> <prop key="H2">h2</prop> </props> </property> </bean> <bean id="databaseIdProvider" class="org.apache.ibatis.mapping.VendorDatabaseIdProvider"> <property name="properties" ref="vendorProperties"/> </bean> <!-- 事務相關控制 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource_wx"/> </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*" propagation="REQUIRED"></tx:method> <tx:method name="find*" propagation="SUPPORTS"/> <tx:method name="list*" propagation="SUPPORTS"/> <tx:method name="get*" propagation="SUPPORTS"/> <tx:method name="select*" propagation="SUPPORTS"/> </tx:attributes> </tx:advice> <!-- 阿里druid spring監控配置 --> <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.icss.ah.*.service.*</value> </list> </property> </bean> <aop:config> <aop:advisor advice-ref="druid-stat-interceptor" pointcut-ref="druid-stat-pointcut" /> </aop:config> <!-- <aop:config proxy-target-class="true"> <aop:pointcut id="beanPointcut" expression="execution(* com.icss.ah.*.service.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="beanPointcut" /> </aop:config> --> </beans>