cglib動態代理
阿新 • • 發佈:2017-10-19
pub spa llb pre [] ets cer int etc
public class CglibProxy implements MethodInterceptor { private Object target; public Object createProxy(Object target) { this.target = target; Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(this.target.getClass()); enhancer.setCallback(this);return enhancer.create(); } @Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { Object result =null ; System.out.println("事務開始"); result = methodProxy.invokeSuper(obj, args); System.out.println("事務結束"); return result; } }
cglib動態代理