/**
* 使用AOP联盟提供的API,用来定义拦截器使用
* @param args
* @throws Throwable
*/
public static void main(String[] args) throws Throwable {
// 我特意这么写用以显示指定拦截器的使用方法
MethodInterceptor interceptor = new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
System.out.println("before...");
Object proceed = methodInvocation.proceed();
System.out.println("after...");
return proceed;
}
};
Object result = interceptor.invoke(new MethodInvocation() {
@Override
public Method getMethod() {
return null;
}
@Override
public Object[] getArguments() {
return new Object[0];
}
@Override
public Object proceed() throws Throwable {
System.out.println("invoke action");
return "HELLO,AOP";
}
@Override
public Object getThis() {
return null;
}
@Override
public AccessibleObject getStaticPart() {
return null;
}
});
System.out.println(result);
}