在 Java 中,“Proxy 代理”通常有三种常见含义,调试方式也不同。下面我分别说明,并给出实用调试技巧。
JDK 动态代理在运行时生成类,类名类似:
com.sun.proxy.$Proxy12
System.out.println(proxy.getClass().getName());
System.out.println(Arrays.toString(proxy.getClass().getInterfaces()));
public Object invoke(Object proxy, Method method, Object[] args) {
System.out.println("调用方法:" + method.getName());
return method.invoke(target, args);
}
JVM 参数:
-Dsun.misc.ProxyGenerator.saveGeneratedFiles=true
代理类会生成在:
com/sun/proxy/$ProxyX.class
用 IDE 反编译即可看逻辑。
-Djava.lang.reflect.Proxy.debug=true
System.out.println(bean.getClass());
com.sun.proxy.$ProxyXXX$$EnhancerBySpringCGLIB$$...logging:
level:
org.springframework.aop: debug
@Around("pointcut()")
public Object around(ProceedingJoinPoint pjp) throws Throwable {
return pjp.proceed();
}
@EnableAspectJAutoProxy(proxyTargetClass = true)
如果你说的是 HTTP / SOCKS 代理:
System.setProperty("http.proxyHost", "127.0.0.1");
System.setProperty("http.proxyPort", "8888");
System.setProperty("javax.net.debug", "all");
invoke() 或切面方法里断点this 和 targetnew Throwable().printStackTrace();
你是哪一种 Proxy?
我可以直接给你针对性的调试示例。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。