Detailed explanation of Druid connection pool configuration in JSP Spring

  • 2021-12-04 19:25:29
  • OfStack

Configuration of Druid Connection Pool in JSP Spring


Configuring bean in applicationContext. xml

<!--  Ali  druid  Database connection pool  --> 
 <bean id="dataSource" class="" 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 initialization size, minimum, maximum  --> 
  <property name="initialSize" value="1" /> 
  <property name="minIdle" value="1" />  
  <property name="maxActive" value="20" /> 

  <!--  Configure the time to get the connection wait timeout  --> 
  <property name="maxWait" value="60000" /> 

  <!--  How long does the configuration interval take place 1 Detects idle connections that need to be closed, in milliseconds  --> 
  <property name="timeBetweenEvictionRunsMillis" value="60000" /> 

  <!--  Configure 1 The minimum time, in milliseconds, for a connection to live in the pool  --> 
  <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" /> 

  <!--  Open PSCache And specifies that on each connection PSCache The size of  --> 
  <property name="poolPreparedStatements" value="true" /> 
  <property name="maxPoolPreparedStatementPerConnectionSize" value="20" /> 

  <!--  Configure the for monitoring statistics interception filters After removing the monitoring interface, sql Unable to count  --> 
  <property name="filters" value="stat" />  

Monitor configuration web. xml



This configuration can access the monitoring interface. After configuration, you can use http://ip: port/Project Name/druid/index. html

Monitor database access performance

Thank you for reading, hope to help everyone, thank you for your support to this site!

Related articles: