标签:
public class UserDaoProxy{ private Object obj; public UserDaoProxy(Object obj) { super(); this.obj = obj; } //给目标对象,生成代理对象 public Object getProxyInstance(){ return Proxy.newProxyInstance( obj.getClass().getClassLoader(), obj.getClass().getInterfaces(), new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { System.out.println("开启事务。。。"); //执行目标对象方法 Object o=method.invoke(obj, args); System.out.println("提交事务。。。。"); return o; } }); } }
标签:
原文地址:http://www.cnblogs.com/may12138/p/5639096.html