Announcement Announcement Module
Collapse
No announcement yet.
Aspect execute twice for Transactional Service methods Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    import org.aspectj.lang.ProceedingJoinPoint;
    import org.aspectj.lang.annotation.*

    @Aspect
    class TestAspect
    {
    @Around("execution (* *.*Service.*SM(..))")
    Object testExecution (ProceedingJoinPoint method)
    {
    println "before method"
    Object o = method.proceed()
    println "after method"
    return o
    }
    }

    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?
Working...
X