配置druid监控spring jdbc代码 [url]http://19950603.blog.51cto.com/9921553/1616566[/url]
Ali Druid 连接池与监控 配置 [url]http://langmnm.iteye.com/blog/2112099[/url]
阿里巴巴 Druid配置监控 官方: [url]https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_StatViewServlet%E9%85%8D%E7%BD%AE[/url]
[b]按需要配置Spring和Web的关联监控[/b]
Web关联监控配置
[url]https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_%E9%85%8D%E7%BD%AEWebStatFilter[/url]
Spring关联监控配置
[url]https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_Druid%E5%92%8CSpring%E5%85%B3%E8%81%94%E7%9B%91%E6%8E%A7%E9%85%8D%E7%BD%AE[/url]
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>
<init-param>
<!-- 允许清空统计数据 -->
<param-name>resetEnable</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<!-- 用户名 -->
<param-name>loginUsername</param-name>
<param-value>druid</param-value>
</init-param>
<init-param>
<!-- 密码 -->
<param-name>loginPassword</param-name>
<param-value>druid</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DruidStatView</servlet-name>
<url-pattern>/druid/*</url-pattern>
</servlet-mapping>
applicationContext.xml
<bean id="druid-stat-interceptor" class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor">
</bean>
<bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut" scope="prototype">
<property name="patterns">
<list>
<value>com.pandy..service.*</value>
</list>
</property>
</bean>
<aop:config>
<aop:advisor advice-ref="druid-stat-interceptor" pointcut-ref="druid-stat-pointcut" />
</aop:config>
<bean id="dataSource" class="com.pandy.framework.core.ds.XBasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<!-- <property name="alias" value="${proxool.alias}" />
<property name="houseKeepingTestSql" value="${proxool.houseKeepingTestSql}" />
<property name="prototypeCount" value="${proxool.prototypeCount}" />
<property name="minimumConnectionCount" value="${proxool.minimumConnectionCount}" />
<property name="maximumActiveTime" value="3600000" /> -->
<!-- 配置这里,才能监控SQL -->
<property name="filters" value="stat,wall" />
</bean>
package com.pandy.framework.core.ds;
import com.alibaba.druid.pool.DruidDataSource;
import com.mysql.jdbc.AbandonedConnectionCleanupThread;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;
/**
* 项目名称: wp_idea_linux
* 功能说明:
* 创建者: Pandy,
* 版权:
* 官网:
* 创建日期: 15-11-13.
* 创建时间: 下午5:21.
* 修改历史:
* -----------------------------------------------
*/
public class XBasicDataSource extends DruidDataSource {
@Override
public void close(){
Enumeration<Driver> drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements()) {
Driver driver = drivers.nextElement();
try {
DriverManager.deregisterDriver(driver);
} catch (SQLException e) {
e.printStackTrace();
}
}
try {
AbandonedConnectionCleanupThread.shutdown();
} catch (InterruptedException e) {
//logger.warn("SEVERE problem cleaning up: " + e.getMessage());
e.printStackTrace();
}
super.close();
}
}
标签:起步,javaWeb,url,druid,E7%,Druid,85%,import,com
From: https://blog.51cto.com/u_3871599/6411163