After this period of study and use of spring, slowly realize the excellent spring, is deeply absorbing the essence of spring, hehe. This is just a simple AOP example, including a pre-notification, a post-notification, a surround notification, and a target object. The main goal of this example is to make it easier to get started with AOP and to find out how to configure the stuff in AOP.
Interface for target object: Istudent.java 1/**
2 *
3 */
4 package Com.dragon.study;
5
6/**
7 * @author dragon
8 *
9 */
Public Interface IStudent {
11
12 public void addstudent (String name);
Target class: Studentimpl.java 1/**
2 *
3 */
4 Package Com.dragon.study.Impl;
5
6 Import com.dragon.study.IStudent;
7
8/**
9 * @author Dragon
10 *
11 */
public class Studentimpl implements Istudent {
13
public void Addstudent (String name) {
System.out.println ("Welcome" +name+ "You join the Spring family!");
16}
17}
18
Pre-notification: Beforeadvice.java 1/**
2 *
3 */
4 Package Com.dragon.Advice;
5
6 Import Java.lang.reflect.Method;
7
8 Import Org.springframework.aop.MethodBeforeAdvice;
9
10/**
* @author Dragon
12 *
13 */
public class Beforeadvice implements Methodbeforeadvice {
15
+ public void before (Method method,object[] args, Object target)
Throws throwable{
18
System.out.println ("This is the Before method of the Beforeadvice class.");
20
21}
22}
23
Post notification: Afteradvice.java
1/**
2 *
3 */
4 Package Com.dragon.Advice;
5
6 Import Java.lang.reflect.Method;
7
8 Import Org.springframework.aop.AfterReturningAdvice;
9
10/**
* @author Dragon
12 *
13 */
public class Afteradvice implements Afterreturningadvice {
15
public void