@Before Example

target object

package com.example.springaopdemo.before;

public class Dog {
    private int id;
    private String name;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void displayDogInfo() {
        System.out.println(id + ":" + name);
    }
}

aspect object:

package com.example.springaopdemo.before;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class DogLogging {
    @Pointcut("execution(* com.example.springaopdemo.before.*.*(..))")
    private void selectAll() {
    }

    /**
     * This is the method which I would like to execute
     * before a selected method execution.
     */
    @Before("selectAll()")
    public void beforeAdvice() {
        System.out.println("before dog method execute...");
    }

}

client:

package com.example.springaopdemo.before;

import com.example.springaopdemo.app.Student;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class DogClient {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        Dog dog = (Dog) context.getBean("dog");
        dog.displayDogInfo();
    }
}

download source code here:
springaopdemo