< Prev
Next >

Spring with AspectJ Annotation

In this tutorial, we are going to explain how to configure the Spring Framework to work with AspectJ using some AspectJ Annotations. For this, we are going to declare and define some important AspectJ properties such as aspect, pointcut, joinpoint and some simple advices using AspectJ Annotation, such as -

Creating the Java class - MarathonRunner

We are going to create a java class named MarathonRunner within the decodejava package and this class contains - Besides this, we are also going to define a couple of getter and setter methods within this class to set the above mentioned properties of MarathonRunner class.

Besides these getter and setter methods, we are going to define two more methods i.e. marathonBegins() and marathonEnds(), which are going to become our joinpoints. Before the execution of these methods(joinpoints), we are going to apply the pointcuts and advices of AspectJ (using AspectJ Annotations in another Java class), later on.

package decodejava;

public class MarathonRunner
String name;
int age;

//Getter method for age
public int getAge() {
	return age;

//Setter method for age
public void setAge(int age) {
	this.age = age;

//Getter method for name
public String getName()
	return name;

//Setter method for name
public void setName(String name) 
	this.name = name;

public void marathonBegins()
System.out.println("Marathon runner has started the race");

public void marathonEnds()
System.out.println("Marathon runner has finished the race");


Class defining pointcuts and advices

Next, we are going to add another Java class named MarathonTimeTracker and in which we are going to define a few AspectJ properties, using AspectJ annotations, such as - pointcut, joinpoints and advices, using AspectJ Annotation, such as -
Please subscribe our social media channels for notifications, we post a new article everyday.

Decodejava Google+ Page Decodejava Facebook Page  DecodeJava Twitter Page

Coming Next
C++ and Python