Druid提供了Spring和Jdbc的关联监控

Druid提供了Spring和Jdbc的关联监控。

配置spring

com.alibaba.druid.support.spring.stat.DruidStatInterceptor是一个标准的SpringMethodInterceptor。可以灵活进行AOP配置。

SpringAOP的配置文档:http://static.springsource.org/spring/docs/current/spring-framework-reference/html/aop-api.html

按类型拦截配置

<beanid="druid-stat-interceptor"

class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor">

</bean>

<beanid="druid-type-proxyCreator"class="com.alibaba.druid.support.spring.stat.BeanTypeAutoProxyCreator">

<!--所有ABCInterface的派生类被拦截监控-->

<propertyname="targetBeanType"value="xxxx.ABCInterface"/>

<propertyname="interceptorNames">

<list>

<value>druid-stat-interceptor</value>

</list>

</property>

</bean>

方法名正则匹配拦截配置

<beanid="druid-stat-interceptor"

class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor">

</bean>

<beanid="druid-stat-pointcut"class="org.springframework.aop.support.JdkRegexpMethodPointcut"

scope="prototype">

<propertyname="patterns">

<list>

<value>com.mycompany.service.*</value>

<value>com.mycompany.dao.*</value>

</list>

</property>

</bean>

<aop:config>

<aop:advisoradvice-ref="druid-stat-interceptor"

pointcut-ref="druid-stat-pointcut"/>

</aop:config>

有些情况下,可能你需要配置proxy-target-class,例如:

<aop:configproxy-target-class="true">

<aop:advisoradvice-ref="druid-stat-interceptor"

pointcut-ref="druid-stat-pointcut"/>

</aop:config>

按照BeanId来拦截配置

<beanid="druid-stat-interceptor"

class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor">

</bean>

<bean

class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">

<propertyname="proxyTargetClass"value="true"/>

<propertyname="beanNames">

<list>

<!--这里配置需要拦截的beanid列表-->

<value>xxx-dao</value>

<value>xxx-service</value>

</list>

</property>

<propertyname="interceptorNames">

<list>

<value>druid-stat-interceptor</value>

</list>

</property>

</bean>

相关推荐