赞
踩
我按照网友的文章做动态代理测试,代码如下:
接口类:
public interface HelloService {
String hello(String name,int money);
}
实现类:
public class HelloServiceImpl implements HelloService {
@Override
public String hello(String name,int money) {
return “Hello ” + name+”,你获得了” + money;
}
}
动态处理类:ProxyFactory
public class ProxyFactory {
private Object object;
public ProxyFactory(Object object){
this.object = object;
}
public Object getProxyInstance(){
return Proxy.newProxyInstance(object.getClass().getClassLoader(),object.getClass().getInterfaces(),new InvocationHandler(){
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable{
System.out.println("开始事务1");
//执行目标对象方法
Object returnValue = method.invoke(object, args);
System
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。