1.maven project to join related dependencies
<dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.29</version> </dependency>
2. Introduction of configuration file database connection related information
<!-- 引入配置文件 --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:jdbc.properties" /> </bean>
3. Configuration of the data source
<BeanId="DataSource"class="Com.alibaba.druid.pool.DruidDataSource"Init-method="Init"Destroy-method="Close" ><PropertyName="Driverclassname"Value="${jdbc.driver}"/><PropertyName="url"Value="${jdbc.url}"/><PropertyName="Username"Value="${jdbc.username}"/><PropertyName="Password"Value="${jdbc.password}"/><!--configuration initialization size, MIN, max--<PropertyName="InitialSize"Value="1"/><PropertyName="Minidle"Value="1"/><PropertyName="Maxactive"Value="Ten"/><!--configuration Gets the time that the connection waits timeout--<PropertyName="Maxwait"Value="10000"/>< how long!--configuration interval to detect idle connections that need to be closed, in milliseconds-and<PropertyName="Timebetweenevictionrunsmillis"Value="60000"/><!--Configure the minimum time for a connection to survive in a pool, in milliseconds--<PropertyName="Minevictableidletimemillis"Value="300000"/><PropertyName="Testwhileidle"Value="True"/><!--It is recommended to configure true to prevent access to a connection that is not available-<PropertyName="Testonborrow"Value="True"/><PropertyName="Testonreturn"Value="False"/><!--open Pscache and specify the size of Pscache on each connection-<PropertyName="Poolpreparedstatements"Value="True"/><PropertyName="Maxpoolpreparedstatementperconnectionsize"Value="/>"<!--here to configure the submission method, the default is true, you can not configure--<PropertyName="Defaultautocommit"Value="True"/><!--Verify that the connection is valid or not, different data configurations are different--<PropertyName="Validationquery"Value="Select 1"/><PropertyName="Filters"Value="Stat"/><PropertyName="Proxyfilters" ><List><ref bean= "LogFilter"/> </list> </ property> </bean> <bean id= "Logfilter" class= "Com.alibaba.druid.filter.logging.Slf4jLogFilter" > <property name=" statementexecutablesqllogenable "value=" False "/> </BEAN>
4. Adding monitoring configuration to Web. xml
<!--connection pooling enable the Web monitoring statistics function start-to-<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><!--connection pooling enable the Web monitoring statistics function end-->
After the configuration is successful, start the Project http://ip:8080/project name/druid/to view SQL monitoring
Druid database connection pool integration into SPRINGMVC