动态代理

public static void main(String[] args) {
        final  ServiceImpl impl =new ServiceImpl();
        UserServce  servce = (UserServce)Proxy.newProxyInstance(ProjexTest.class.getClassLoader(), new Class[]{UserServce.class}, new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("代理执行前");
                try {
                    return method.invoke(impl, args);
                } finally {
                    System.out.println("代理执行后");
                }
            }
        });
        servce.get();
}

  https://blog.csdn.net/weixin_39715061/article/details/80394751

posted @ 2020-03-05 10:32  胡一生  阅读(161)  评论(0编辑  收藏  举报