Javamelody, Spring & AspectJ

Javamelody is a tool for monitoring Java applications. It measures and calculates statistics of JVM state, JDBC calls, Spring, EJB or Guice managed beans’ methods execution. Javamelody provides Spring configuration (monitoring-spring.xml), which You can include in Your Spring configuration out of the box.

<beans xmlns=""    xmlns:xsi=""   xmlns:tx=""     xsi:schemaLocation="                             ">

    <bean id="monitoringAdvisor" class="net.bull.javamelody.MonitoringSpringAdvisor">
        <property name="pointcut">
            <bean class="net.bull.javamelody.MonitoredWithAnnotationPointcut"></bean>

    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"></bean>

    <bean id="springDataSourceBeanPostProcessor" class="net.bull.javamelody.SpringDataSourceBeanPostProcessor"></bean>

Above configuration creates proxies on annotated classes or methods automatically. It can fail in many circumstances. E.g. if You don’t use interfaces or use aspectj with some type of code weaving. To avoid these problems you need to configure Spring monitoring in a slightly different AspectJ way:

<beans xmlns=""        xmlns:xsi=""        xmlns:context=""        xmlns:aop=""        xsi:schemaLocation="      ">

    <aop:config proxy-target-class="true">
        <aop:advisor advice-ref="monitoringAdvice" pointcut-ref="allPublicFacadeOperations"></aop:advisor>

    <bean id="monitoringAdvice" class="net.bull.javamelody.MonitoringSpringInterceptor"></bean>


3 thoughts on “Javamelody, Spring & AspectJ

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.