JETM Springframework 1.x/2.x integration
This page describes the generic Springframework 1.x/2.x JETM integration. If you already use Spring 2.x schema based configuration please use JETM Spring 2.x integration.
Be aware that these prerequisites and constraints apply.
Performance monitoring step-by-step
The Spring Framework comes with an extremely powerful concept called "autoproxy" facility that can automatically proxy selected bean definitions. These proxies can be used to intercept calls to these beans and thus record execution times.
Step I: Initialize JETM monitoring
The following two bean definitions enable performance monitoring in your spring managed application. First we registered an instance of EtmMonitor, second we register an Interceptor that will be used later.
<bean id="etmMonitor" class="etm.core.monitor.NestedMonitor" init-method="start" destroy-method="stop"/> <bean id="etmMethodCallInterceptor" class="etm.contrib.aop.aopalliance.EtmMethodCallInterceptor" autowire="constructor"/>
Since the instance of EtmMonitor should exist globally you need to ensure that the bean definition happens in your spring configuration root. Otherwhise child definitions may not be able to access the monitor.
Step II: Monitor Spring managed beans
The class BeanNameAutoProxyCreator is one option to enable the "autoproxy" facility. It creates proxies of selected beans and applies interceptors to them. In the example below we apply our previously registered EtmMethodCallInterceptor to beans that end with Service. You can use concrete names or wildcards if you want.
<bean id="etmAutoProxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator" singleton="false"> <property name="interceptorNames"> <list> <value>etmMethodCallInterceptor</value> </list> </property> <property name="beanNames"> <value>*Service</value> </property> </bean>
Step III: Access aggregated results
The standalone HTTP console provides access to aggregated performance results. Simply add the following fragment to your Spring configuration and point your browser to http://{HOSTNAME}:40000 to access it.
<bean id="etmHttpConsole" class="etm.contrib.console.HttpConsoleServer" init-method="start" destroy-method="stop" autowire="constructor"/>
If your application is a web application you probably want to use the servlet based monitoring console instead. See Spring web integration for further details.
Monitoring alternative: EtmProxyFactoryBean
Similar to Spring framework TransactionProxyFactoryBean JETM ships with the class EtmProxyFactoryBean that may be used to enhance Spring beans with performance monitoring code. The example below creates an instance of foo.bar.SomeService using a template Factory.
<bean id="etmProxyTemplate" abstract="true" class="etm.contrib.aop.spring.EtmProxyFactoryBean"> <property name="etmMonitor" ref="etmMonitor"/> </bean> <bean id="someService" parent="etmProxyTemplate"> <property name="target"> <bean class="foo.bar.SomeService" autowire="constructor"/> </property> </bean>