Thursday, 15 September 2011

Defining Spring's AspectJ Advice Types

My blog from a couple of days ago defined the AspectJ, AOP’s term ‘advice’ as the code that runs when your application execution reaches a join point in a point cut. What I neglected to mention is that there are several different types of advice all applied to method executions and these are summarized in the table below:

@BeforeThe advice method gets called before the method defined in your point cut.
@AfterThe advice code gets called after the method defined by your point cut has finished executing.
@AroundAn advice that combines the @Before and @After, executing some code before the method in the point cut and some after.
@AfterThrowingAn advice that executes after an exception have been thrown, and before it’s caught.

The Guy’s at Spring have documented how to use these annotations in this document.

No comments: