可以通过注解的方式来自定义代理对象的创建,同时也可以通过SpringAPI,手动编程的方式来创建代理对象。
几个重要的API:
- ProxyFactory
- MethodInterceptor
- Advice
- AfterReturningAdvice
- MethodBeforeAdvice
public class Man implements Person{
@Override
public String eat(String someThing) {
System.out.println("执行代理方法-->吃:"+someThing);
return someThing;
}
}
public interface Person {
String eat(String someThing);
}
package com.blog.test.aop;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.framework.ProxyFactory;
import org.aopalliance.intercept.MethodInterceptor;