AspectJ with weblogic

左心房为你撑大大i 提交于 2019-12-04 17:01:19

Found the answer. Note that this is only for LTW (Load Time Weaving)

There are primarily 4 key components from a weaving perspective:

  1. The target classes that you want to weave: All those that you want to Aspect on should be in the classpath. For a typical application, they will be in your applications WEB-INF/lib or WEB-INF/classes, so let them be there. No changes here.

  2. AOP.xml: This is used by the weaver to discover the Aspect and Weaver configuration. This should also be available in the classpath. You can put this in a JAR in /lib folder, so that its configuration is available for all applications (EARs and WARs).

  3. The Aspect class(es): If using annotations for Aspect class, then "it also needs to be weaved". AspectJ weaver adds some special methods (like aspectOf) to this class. Hence it must be available in the classpath. This can be part of the same JAR as for (2). If you've already compiled this using ajc (the aspectJ compiler), then it can be put in the bootclasspath also (but giving no real advantage over the lib folder).

Note: Since this class needs to be woven, it must be present in the tag in the AOP.xml, other than the list of classes/packages you want to Aspect on

  1. The weaver itself (which is in aspectjweaver.jar): This should be available via java agent, so add the following line to the /bin/setDomainEnv.cmd

    SET JAVA_OPTIONS=%JAVA_OPTIONS% -javaagent:%ASPECT_HOME%\lib\aspectjweaver.jar If using setDomainEnv.sh, you will need to do an EXPORT JAVA_OPTIONS also.

So, for LTW there is really no need of

  • fiddling with the bootclasspath (as I was),
  • aspectjrt.jar in any of the classpaths

Have you tried to also add aspectjrt.jar to the classpath? Actually it should be a subset of aspectweaver.jar and not necessary, but maybe you want to try it anyway.

Update: Hm, maybe the problem is that you put your aspect on the boot classpath instead of the normal classpath and even prepend it, i.e. you make it be found first, maybe even before the Java agent. Maybe you want to change that.

Because I am not an application server user and not a Weblogic expert in particular, you might want to consult http://rajiv-kuriakose.blogspot.de/2011/03/aspectj-example-with-weblogic-server.html for a sample configuration.

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