mysql
<!-- 配置druid连接池 --> <context:property-placeholder location="classpath:jdbc.properties"/> <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="minIdle" value="${jdbc.minIdle}" /> <property name="maxActive" value="${jdbc.maxActive}" /> <property name="maxWait" value="${jdbc.maxWait}" /> <property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" /> <property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}" /> <property name="validationQuery" value="${jdbc.validationQuery}" /> <property name="testWhileIdle" value="${jdbc.testWhileIdle}" /> <property name="testOnBorrow" value="${jdbc.testOnBorrow}" /> <property name="testOnReturn" value="${jdbc.testOnReturn}" /> <property name="filters" value="${jdbc.filters}" /> <property name="proxyFilters"> <list> <ref bean="logFilter" /> </list> </property> </bean> <bean id="logFilter" class="com.alibaba.druid.filter.logging.Slf4jLogFilter"> <property name="statementExecutableSqlLogEnable" value="false" /> </bean>
jdbc.url=jdbc:mysql://192.168.1.81:3306/sinotn_safe?useUnicode=true&characterEncoding=utf-8 jdbc.username=sinotn jdbc.password=123456 jdbc.initialSize=1 jdbc.minIdle=1 jdbc.maxActive=200 jdbc.maxWait=60000 jdbc.timeBetweenEvictionRunsMillis=60000 jdbc.minEvictableIdleTimeMillis=30000 jdbc.validationQuery=SELECT 'x' jdbc.testWhileIdle=true jdbc.testOnBorrow=false jdbc.testOnReturn=false jdbc.filters=stat
oracle
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <!-- 基本属性 url、user、password --> <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:ORCL" /> <property name="username" value="gxsafe20180527" /> <property name="password" value="123456" /> <!-- 配置初始化大小、最小、最大 --> <property name="initialSize" value="1" /> <property name="minIdle" value="1" /> <property name="maxActive" value="100" /> <!-- 配置获取连接等待超时的时间 --> <property name="maxWait" value="60000" /> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="60000" /> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="300000" /> <property name="validationQuery" value="SELECT 'x' FROM DUAL " /> <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" /> <property name="proxyFilters"> <list> <ref bean="logFilter" /> </list> </property> </bean> <bean id="logFilter" class="com.alibaba.druid.filter.logging.Slf4jLogFilter"> <property name="statementExecutableSqlLogEnable" value="false" /> </bean>
web.xml
1 <!-- 连接池 启用 Web 监控统计功能 start --> 2 <servlet> 3 <servlet-name>DruidStatView</servlet-name> 4 <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class> 5 <init-param> 6 <!-- 用户名 --> 7 <param-name>loginUsername</param-name> 8 <param-value>druid</param-value> 9 </init-param> 10 <init-param> 11 <!-- 密码 --> 12 <param-name>loginPassword</param-name> 13 <param-value>druid</param-value> 14 </init-param> 15 </servlet> 16 <servlet-mapping> 17 <servlet-name>DruidStatView</servlet-name> 18 <url-pattern>/druid/*</url-pattern> 19 </servlet-mapping> 20 <filter> 21 <filter-name>druidWebStatFilter</filter-name> 22 <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class> 23 <init-param> 24 <param-name>exclusions</param-name> 25 <param-value>/public/*,*.js,*.css,/druid*,*.jsp,*.swf</param-value> 26 </init-param> 27 <init-param> 28 <param-name>principalSessionName</param-name> 29 <param-value>sessionInfo</param-value> 30 </init-param> 31 <init-param> 32 <param-name>profileEnable</param-name> 33 <param-value>true</param-value> 34 </init-param> 35 </filter> 36 <filter-mapping> 37 <filter-name>druidWebStatFilter</filter-name> 38 <url-pattern>/*</url-pattern> 39 </filter-mapping> 40 <!-- 连接池 启用 Web 监控统计功能 end -->