This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Trying to get a basic "afterThrowing" advice working

Sep 9th, 2010, 09:14 PM

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).

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.

Comment

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.