Spring AspectJ Annotation Style

Step 1 – Create new maven-based java project

You can create normal java project and add jar file to your project build path. But it’s faster using maven as maven is integrated with Eclipse IDE; so you don’t need to manually install it. You need spring-context and  aspectjweaver dependencies.

Project Object Model (POM.XML)

Step 2 Create Bean class

Select your src folder of your project, copy the below code and press CTRL + V to paste the code. Eclipse IDE will automatically create new class with correct package.

The Lifecycle class  contains 5 methods init, service(1,2,3) & destroy.

  • init: initialize system parameters
  • service 1,2,3: implement business logic
  • destroy: to kill process, garbage collection…

But the init & destroy methods are not implemented here.

Step 3 AspectJ Class

Step 4 Create annotated type Configuration class

 

Step 5 Create test class

Compile & Run the application

Go to Project -> Clean to clean & build the project. Eclipse will download & add maven dependencies to your project build path; then compile your classes.

Right click to the test class; select Run As -> Java Application