Getting started AOP with Spring Framework

We are going to do small program using Spring Framework to study the basics of the Aspect-Oriented Programming

In this example I will create simple Java Console application
You will need aspectjrt.jar, aspectjweaver.jar and spring-aop.jar file for this application in addition to basic Spring jar file.

First you can create the Car bean class

I have used @Component annotation to make this class as Spring Bean

Next I will create Log class with show method and this show method will be called before the getName() is called

You have @Aspect and @EnableAspectJAutoProxy annotation which we need for Aspect Orined Programming.
@Before("execution(* com.kayak.Car.getName(..))") code tells to spring ececute the show method before calling the getName() of the Car class

So to run above code you can use the following main method

So you will get the following output