Combining spring using Ali Druid connection Pooling Configuration method

Source: Internet
Author: User
Tags connection pooling

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

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.