p { margin-bottom: 0.21cm; }
public class MyProxyFactoryBean {
// 第一个参数 通知 建议对象 第二个参数 返回对象 实体对象
public Object getProxy( final Advice advice, final Object target) {
Object proxy = Proxy. newProxyInstance (
target.getClass().getClassLoader()
,target.getClass().getInterfaces(),
new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method,
Object[] args) throws Throwable {
// 前置通告
advice.afterMethod(method);
// 执行对象的方法 使用的反射技术
Object reVal = method.invoke(target, args);
// 后置通知
advice.beforMethod(method);
return reVal;
}
});
return proxy;
}
}