AspectJ - Weaving with custom ClassLoader at runtime

拟墨画扇 提交于 2019-12-05 10:20:59

OK I found out what it was, and it doesn't work quite the way I intended it, but here is a workaround:

Just do a @Before("execution(* mypackage.MyInterface.*())") instead of call. This works even if the class was loaded manually and at runtime by a custom class loader. This is because AspectJ doesn't care about calls that are done with using Method.invoke(...). I hope someone else can use this workaround.

Here is a link to the documentation containing the memorable info:

For example, the call pointcut does not pick out reflective calls to a method implemented in java.lang.reflect.Method.invoke(Object, Object[]).

http://www.eclipse.org/aspectj/doc/released/progguide/implementation.html

If you have a different solution, please don't hesitate to answer!

If I'm not mistaken, AspectJ can't weave JDK classes. That would explain this:

For example, the call pointcut does not pick out reflective calls to a method implemented in java.lang.reflect.Method.invoke(Object, Object[]).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!