1. dataSource中增加
<property name="filters" value="stat,wall"/>
2. spring 中增加(spring的支持)
<!-- druid spring monitor setting --> <!-- 开启@AspectJ AOP代理 --> <bean id="druid-stat-interceptor" class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor"/> <bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut" scope="prototype"> <property name="patterns"> <list> <value>com.beta.mss.core.service.*</value> </list> </property> </bean> <aop:config proxy-target-class="true"> <aop:advisor advice-ref="druid-stat-interceptor" pointcut-ref="druid-stat-pointcut"/> </aop:config>
需要注意的是这里的patterns中一般只监控service,controller监控不到,同时spring代理使用CGLib的代理方式,但是CGLib不能代理final类或被private,final修饰的方法,CGLib面对具体代理类,不能是接口,jdk的代理是面向接口的。
3. web.xml
<!-- druid url monitor setting start --> <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> <init-param> <param-name>profileEnable</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>DruidWebStatFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- druid url monitor setting end -->
<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>name</param-value> </init-param> <init-param> 密码 <param-name>loginPassword</param-name> <param-value>pwd</param-value> </init-param> --> </servlet> <servlet-mapping> <servlet-name>DruidStatView</servlet-name> <url-pattern>/druid/*</url-pattern> </servlet-mapping>