【Spring】动态代理模板

动态代理模板

/**
 * Description :
 * 公用这个类,自动生成代理类
 *
 * @author : AirCL
 * Date : 2021/2/4
 * Time : 20:27
 */
public class ProxyInvocationHandler implements InvocationHandler {

    //被代理的按口
    private Object target;

    public void setTarget(Object target) {
        this.target = target;
    }

    //生成得到代理类
    public Object getProxy() {
        return Proxy.newProxyInstance(this.getClass().getClassLoader(),
                target.getClass().getInterfaces(), this);
    }

    //处理代理实例,并返间结果:
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object result = method.invoke(target, args);
        return result;
    }
}
原文地址:https://www.cnblogs.com/AirCL/p/14374850.html