Manually (clients)

To handle manually the interception you need to import commons-monitoring-aop. Then you can rely on org.apache.commons.monitoring.aop.MonitoringProxyFactory.

org.apache.commons.proxy.ProxyFactory key defines the proxy factory to use to create proxies For instance to use javassist you set it to org.apache.commons.proxy.factory.javassist.JavassistProxyFactory (and you’ll include javassist in your application).

Then the API is quite simple:

final MyClient client = MonitoringProxyFactory.monitor(MyClient.class, getMyClientInstance());


You just need to decorate your CDI bean/method with the interceptor binding org.apache.commons.monitoring.cdi.Monitored.

For instance:

public class MyMonitoredBean {
    public void myMethod() {
        // ...

Note: in some (old) CDI implementation you’ll need to activate the monitoring interceptor: org.apache.commons.monitoring.cdi.CommonsMonitoringInterceptor.

Note: we are working to make it configurable.


Using org.apache.commons.monitoring.spring.BeanNameMonitoringAutoProxyCreator you can automatically add monitoring to selected beans.

<bean class="org.apache.commons.monitoring.spring.BeanNameMonitoringAutoProxyCreator">
  <property name="beanNames">

An alternative is to use org.apache.commons.monitoring.spring.PointcutMonitoringAutoProxyCreator which uses a org.springframework.aop.Pointcut to select beans to monitor.


To use AspectJ weaver (it works with build time enhancement too but it is often less relevant) just configure a custom concrete aspect defining the pointcut to monitor:

    <concrete-aspect name="org.apache.commons.aspectj.MyMonitoringAspectJ"
      <pointcut name="pointcut" expression="execution(* org.apache.commons.monitoring.aspectj.AspectJMonitoringTest$MonitorMe.*(..))"/>

    <include within="org.apache.commons.monitoring.aspectj.AspectJMonitoringTest$MonitorMe"/>

See AspectJ documentation for more information.