1. Data sources
<!--Configure the data source - <Beanname= "DataSource"class= "Com.alibaba.druid.pool.DruidDataSource"Init-method= "Init"Destroy-method= "Close"> < Propertyname= "Driverclassname"value= "${jdbc.drivername}" /> < Propertyname= "url"value= "${jdbc.url}" /> < Propertyname= "username"value= "${jdbc.username}" /> < Propertyname= "Password"value= "${jdbc.password}" /> <!--Initialize connection size - < Propertyname= "InitialSize"value= "${initialsize}" /><!--<property name= "initialsize" value= "0"/> - <!--Connection Pool Maximum number of connections used - < Propertyname= "Maxactive"value= "${maxactive}" /><!--<property name= "maxactive" value= "/> " - <!--Connection Pool Max idle <property name= "Maxidle" value= "${maxidle}"/> - <!--Connection Pool min idle - < Propertyname= "Minidle"value= "${minidle}" /> <!--Get connection Maximum wait time - < Propertyname= "Maxwait"value= "${maxwait}" /> <!--<property name= "poolpreparedstatements" value= "true"/> <property name= " Maxpoolpreparedstatementperconnectionsize "value="/> - < Propertyname= "Validationquery"value= "${validationquery}" /> < Propertyname= "Testonborrow"value= "${testonborrow}" /> < Propertyname= "Testonreturn"value= "${testonreturn}" /> < Propertyname= "Testwhileidle"value= "${testwhileidle}" /> <!--How often the configuration interval is detected to detect idle connections that need to be closed, in milliseconds - < Propertyname= "Timebetweenevictionrunsmillis"value= "${timebetweenevictionrunsmillis}" /> <!--configures the minimum lifetime of a connection in a pool, in milliseconds - < Propertyname= "Minevictableidletimemillis"value= "${minevictableidletimemillis}" /> <!--turn on the removeabandoned feature - < Propertyname= "removeabandoned"value= "${removeabandoned}" /> <!--1800 seconds, that's 30 minutes. - < Propertyname= "Removeabandonedtimeout"value= "${removeabandonedtimeout}" /> <!--output error log when abanded connection is closed - < Propertyname= "logabandoned"value= "${logabandoned}" /> <!--Monitoring Database - < Propertyname= "Filters"value= "${filters}" /> </Bean>
2.jdbc
Jdbc.drivername=com.mysql.jdbc.driverjdbc.url=jdbc:mysql://192.168.0.100:3306/databasename?useunicode=true &characterencoding=utf-8&zerodatetimebehavior=converttonulljdbc.username= Rootjdbc.password=123456initialsize=0maxactive=20maxidle=20minidle=0maxwait=10000validationquery=select 1testonborrow=falsetestonreturn=falsetestwhileidle=truetimebetweenevictionrunsmillis= 6000minevictableidletimemillis=25200000removeabandoned=trueremoveabandonedtimeout=1800logabandoned=truefilters =stat
3.web.xml Add the following configuration
<!--Connection Pool Monitoring - <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>
4. Connection Pool Monitoring
Start the service and access the HTTP://LOCALHOST:8080/project address/druid/index.html
Combining spring using Ali Druid connection Pooling Configuration method