Spring AOP – AspectJ Annotation Example

In my previous tutorial I have shown how to write Spring AOP using XML configuration and in this tutorial I am going to show you how to write Annotation based Spring AOP using @AspectJ. This example creates annotation examples with @Aspect, @Pointcut, @Before, @After, @Around, @AfterReturning, @AfterThrowing Advice. @AspectJ is a style to declare aspects in a Java class using annotation. @EnableAspectJAutoProxy annotation is used in Java configuration to enable @AspectJ. To work with spring AOP and @AspectJ support, we need to create a class annotated with @Aspect annotation. Inside @Aspect annotated class we can create our pointcut and using pointcut we can also create our advice. Spring AOP is used for different purposes such as logging, transaction management, handling with exception and validating return value of a method.

Continue reading “Spring AOP – AspectJ Annotation Example”

Spring AOP (Aspect Oriented Programming) Example

With this tutorial we will see how to use Aspect Oriented Programming in Spring Framework. AOP is used in the Spring Framework to provide declarative enterprise services. It is also used to allow users to implement custom aspects, complementing their use of OOP with AOP.

We will demonstrate how to create and apply some central AOP concepts. In short we will create all types of advices, we will use a pointcut and an advisor over an advice and we will check on some special features of Spring in interceptors and proxy beans.

Our preferred development environment is Eclipse. We are using Eclipse Kepler version. We are also using Spring version 3.2.8 and the JDK 1.6.

Make sure you have the list of required jar files in your classpath. Continue reading “Spring AOP (Aspect Oriented Programming) Example”