AspectJ - 本机方法调用的切入点
是否可以使用 AspectJ 在本机方法调用上设置切入点?我尝试了以下方面:
public aspect EmailAspect {
pointcut conn() : call(* java.net.PlainSocketImpl.socketConnect(..));
before() : conn() {
System.out.println("Connecting");
}
}
但它不起作用。我也没有通过谷歌搜索找到太多相关信息(除了这个 http://blog.jayway.com/2007/02/16/static-mock-using-aspectj,但是尚不清楚是否可能以及如何做; 它)。
我尝试在 Eclipse 中调试我的测试代码(仅连接到某些 TCP 本地主机端口),并且 Eclipse 在 socketConnect() 断点处停止。
谢谢。
更新
这可能是原因:
Is it possible to set pointcut on native method call with AspectJ? I tried following aspect:
public aspect EmailAspect {
pointcut conn() : call(* java.net.PlainSocketImpl.socketConnect(..));
before() : conn() {
System.out.println("Connecting");
}
}
But it doesn't work. I also didn't find much relevant info via googling (except this http://blog.jayway.com/2007/02/16/static-mock-using-aspectj, however it's not clear if it's possible & how to do it).
I tried to debug my test code (which only connects to some TCP localhost port) in Eclipse and eclipse stopped at socketConnect() breakpoint.
Thank you.
UPDATE
This is probably the cause:
AspectJ - Load-time weaving, privileged aspect and pointcut on private method of JRE class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PlainSocketImpl 是在 JDK 提供的 jar 中,对吧?您可能会发现有关编织到 jar 中的问题很有帮助。显然,在你编织了你的方面之后,你需要记住使用编织的罐子而不是原来的罐子来运行。
PlainSocketImpl is in a jar provided by the JDK, right? You may find the question about weaving into jars helpful. Apparently after you weave in your aspect, you need to remember to run using the woven jars rather than the original.
如果此电子邮件为真,则一旦声明了方法本机,Java 将编写直接跳转到底层 C++/C 机器代码的字节码。这意味着 AspectJ 无需拦截任何内容,无论是编译时、编译后时间还是加载时编织。
If this e-mail is true, once a method is declared native, Java will write bytecode that jumps directly to the underlying C++/C machine code. This means there is nothing to intercept for AspectJ, regardless whether it is compile time, post-compile time, or load-time weaving.