当前位置:   article > 正文

debug模式下动态代理invoke方法重复执行问题_invocationhandler的invoke方法 会执行多次

invocationhandler的invoke方法 会执行多次

我按照网友的文章做动态代理测试,代码如下:
接口类:
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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/225422
推荐阅读
相关标签
  

闽ICP备14008679号