Detailed description of Druid connection pool configuration in JSP Spring, springdruid

Source: Internet
Author: User

Detailed description of Druid connection pool configuration in JSP Spring, springdruid

Druid connection pool configuration in JSP Spring

Jdbc. properties

url=jdbc:postgresql://***.***.***.***:****/****username=***password=***

Configure bean in applicationContext. xml

<! -- Alibaba druid database connection pool --> <bean id = "dataSource" class = "com. alibaba. druid. pool. druidDataSource "init-method =" init "destroy-method =" close "> <! -- Basic attribute url, user, password --> <property name = "url" value = "$ {url}"/> <property name = "username" value = "$ {username} "/> <property name =" password "value =" $ {password} "/> <! -- Configure the initialization size, minimum, and maximum --> <property name = "initialSize" value = "1"/> <property name = "minIdle" value = "1"/> <property name = "maxActive" value = "20"/> <! -- Configure the timeout time for obtaining connections --> <property name = "maxWait" value = "60000"/> <! -- Configure the interval for a test to detect idle connections that need to be closed, in milliseconds --> <property name = "timeBetweenEvictionRunsMillis" value = "60000"/> <! -- Configure the minimum time for a connection to survive in the pool, unit: millisecond --> <property name = "minEvictableIdleTimeMillis" value = "300000"/> <property name = "validationQuery" value = "SELECT 'x'"/> <property name = "testWhileIdle" value = "true"/> <property name = "testOnBorrow" value = "false"/> <property name = "testOnReturn" value = "false"/> <! -- Enable PSCache, specify the PSCache size for each connection --> <property name = "poolPreparedStatements" value = "true"/> <property name = "maxPoolPreparedStatementPerConnectionSize" value = "20"/> <! -- Configure the filters intercepted by monitoring statistics, and the SQL statement on the monitoring page cannot be used for statistics after removal --> <property name = "filters" value = "stat"/> </bean>

Monitoring configuration web. xml

<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>  </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>  </servlet>  <servlet-mapping>    <servlet-name>DruidStatView</servlet-name>    <url-pattern>/druid/*</url-pattern>  </servlet-mapping>

This configuration allows you to access the monitoring page. After configuration, you can use http: // ip: port/project name/druid/index.html

Monitor database access performance

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.