Suresh Payankannur

Tuesday, April 17, 2012

Tracing runtime execution flow with Spring

Spring has some little known built-in interceptor classes which can come in handy to enable method tracing at runtime. This will be useful to understand the system behavior if something goes wrong and one want to turn on tracing the flow of execution, even though there are not enough debug/trace information present in the code.

org.springframework.aop.interceptor package has some pre-built classes which can be easily configured to enable tracing and timing of method executions using AOP instrumentation.

  1. SimpleTraceInterceptor: Will do method level tracing.
  2. DebugInterceptor: Will provide the same information as SimpleTraceInterceptor with additional count indicating the number of times the method has been called.
  3. PerformanceMonitorInterceptor: Logs the method execution timings.
There are few other built in interceptors for Jamon based performance monitoring, throttling the number of concurrent calls to the method etc. These interceptors are very simple, but can come in handy in several situations. I would explain how to configure such an interceptor in a Spring setup.

Spring Configuration







useDyamicLogger will log the trace/debug meesages under the logger defined for the intercepted method. For example, with useDyanmicLogger=true, the logs will be under the logger com.mycompany.service.MyService. Otherwise, the log will be under org.springframework.aop.DebugInterceptor.

Another point to note is that if the interception needs to be done for actual classes (as opposed to interfaces), then CGLIB libraries should be in the classpath as explained in

1 comment:

Blog Archive

Scroll To Top