Announcement Announcement Module
No announcement yet.
Trying to get a basic "afterThrowing" advice working Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trying to get a basic "afterThrowing" advice working

    Remarkably, I'm still new to Spring AOP and am trying to figure out how to handle what I think is a pretty straightforward use case.

    We can argue about the architectural appropriateness, but putting that aside for a moment, I just wanted to write an aspect that could intercept exceptions being thrown from any Struts actions and log them (there is other error handling / presentation logic, but that is orthogonal to the logging concern).

    So here's the relevant Spring configuration:

            <aop:aspect id="logStrutsActionThrowables" ref="throwableLogger">
                <aop:pointcut id="strutsActionExecution"  expression="execution(**.*(..))"/>
                <aop:after-throwing pointcut-ref="strutsActionExecution" throwing="pThrowable" method="log"/>
    The Java class represented by the "throwableLogger" bean has one method, log(), that takes a Throwable as an argument.

    We also have a strutsSpring.xml config file that registers each Struts action as a Spring bean, which I can also attach in a reply.

    So what am I doing wrong? Is it not appropriate to specify Throwable as the parameter? Does it need to be Exception, as that is what is part of the Struts action's signature? Or is that not relevant, as a Throwable is an Exception.

    I tried to test this by temporarily modifying one of our Struts actions to throw an AritmeticException upon executing a division by 0.

    I'm open to any and all suggestions.

    Thanks in advance.


  • #2
    1) Make sure the aop config is loaded in the same ApplicationContext not a parent or child
    2) Make sure that your struts action are actually used, make sure your spring/struts integration works.


    • #3
      Thank you

      Sorry for the ridiculously late reply. You pinpointed our exact problem: we had the AOP config for the Struts actions defined outside of the app context config XML that defines those actions as Spring beans.

      Once we moved the AOP config over, the aspect worked.

      Thank you,