zoukankan      html  css  js  c++  java
  • Druid连接池及监控在spring中的配置

    Druid连接池及监控在spring配置如下:

    [html] view plaincopy
     
     
    1. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">   
    2.     <!-- 基本属性 url、user、password -->  
    3.     <property name="url" value="${jdbc_url}" />  
    4.     <property name="username" value="${jdbc_user}" />  
    5.     <property name="password" value="${jdbc_password}" />  
    6.         
    7.     <!-- 配置初始化大小、最小、最大 -->  
    8.     <property name="initialSize" value="1" />  
    9.     <property name="minIdle" value="1" />   
    10.     <property name="maxActive" value="20" />  
    11.    
    12.     <!-- 配置获取连接等待超时的时间 -->  
    13.     <property name="maxWait" value="60000" />  
    14.    
    15.     <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->  
    16.     <property name="timeBetweenEvictionRunsMillis" value="60000" />  
    17.    
    18.     <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->  
    19.     <property name="minEvictableIdleTimeMillis" value="300000" />  
    20.     
    21.     <property name="validationQuery" value="SELECT 'x'" />  
    22.     <property name="testWhileIdle" value="true" />  
    23.     <property name="testOnBorrow" value="false" />  
    24.     <property name="testOnReturn" value="false" />  
    25.    
    26.     <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->  
    27.     <property name="poolPreparedStatements" value="true" />  
    28.     <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />  
    29.    
    30.     <!-- 配置监控统计拦截的filters,去掉后监控界面sql无法统计 -->  
    31.     <property name="filters" value="stat" />   
    32. </bean>  

     只要配置initialSize,maxActive就可以,目前这样的配置已经能够使用连接池,加入其实配置性能不好,官方文档里也不没加其它属性,连接池jar包免费下载

    然后是监控的配置:

    web.xml

    [html] view plaincopy
     
     
    1. <span style="white-space:pre">  </span><filter>  
    2.         <filter-name>DruidWebStatFilter</filter-name>  
    3.         <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>  
    4.         <init-param>  
    5.             <param-name>exclusions</param-name>  
    6.             <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value>  
    7.         </init-param>  
    8.       </filter>  
    9.       <filter-mapping>  
    10.         <filter-name>DruidWebStatFilter</filter-name>  
    11.         <url-pattern>/*</url-pattern>  
    12.       </filter-mapping>  

    filter可以监控webURl 访问

    [html] view plaincopy
     
    1. <span style="white-space:pre">  </span><servlet>  
    2.         <servlet-name>DruidStatView</servlet-name>  
    3.         <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>  
    4.     </servlet>  
    5.     <servlet-mapping>  
    6.         <servlet-name>DruidStatView</servlet-name>  
    7.         <url-pattern>/druid/*</url-pattern>  
    8.     </servlet-mapping>  

    该配置可以访问监控界面,配置好后,访问http://ip地址:端口号/项目名/druid/index.html即可监控数据库访问性能。

    Druid连接池-阿里巴巴开源JDBC组件

  • 相关阅读:
    背水一战 Windows 10 (26)
    背水一战 Windows 10 (25)
    背水一战 Windows 10 (24)
    背水一战 Windows 10 (23)
    背水一战 Windows 10 (22)
    背水一战 Windows 10 (21)
    背水一战 Windows 10 (20)
    背水一战 Windows 10 (19)
    背水一战 Windows 10 (18)
    背水一战 Windows 10 (17)
  • 原文地址:https://www.cnblogs.com/ThinkVenus/p/6853781.html
Copyright © 2011-2022 走看看