Results 1 to 3 of 3

Thread: Trying to get a basic "afterThrowing" advice working

  1. #1
    Join Date
    Sep 2010
    Posts
    3

    Question 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:

    Code:
        <aop:config>
            <aop:aspect id="logStrutsActionThrowables" ref="throwableLogger">
                <aop:pointcut id="strutsActionExecution"  expression="execution(* com.company.product.admin.action..*.*(..))"/>
                <aop:after-throwing pointcut-ref="strutsActionExecution" throwing="pThrowable" method="log"/>
            </aop:aspect>  
        </aop:config>
    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.

    -Mike

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2010
    Posts
    3

    Default 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,
    Mike

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •