Jun 17th, 2011, 12:26 PM
Aspect execute twice for Transactional Service methods
Hi, I want to perform some specific action when a method in a Service is executed. I create an Aspect that intercepts by execution the method, but if Service has Transactional = true the Aspect is executed twice. If Transactional = false the Aspect executes only once as I need.
The code of the Aspect (for testing the problem) is
@Around("execution (* *.*Service.*SM(..))")
Object testExecution (ProceedingJoinPoint method)
println "before method"
Object o = method.proceed()
println "after method"
I debugged the code, when the Aspect is invoked the first time and the Line Object o = method.proceed() is executed, if the Service where the method belongs has Transactional = true, the Aspect reenters provoking double messages before and after.
Can I some how avoid the double execution of the Aspect for Transactional Service?
Tags for this Thread