Why server complaining about aspectOf is missing?

邮差的信 提交于 2019-12-22 04:54:06

问题


I am currently trying to inject Spring bean in AspectJ like the code shown below, anyhow I the server (WAS Liberty Profile) keep complaining the method aspectOf is missing. May I know how could I solve this problem?

application-context.xml

<aop:aspectj-autoproxy/>
<import resource="/context-file-A.xml"/>

context-file-A.xml

<bean id="loggingAspect" class="com.huahsin.LoggingAspect" factory-method="aspectOf">

JAVA code

@Aspect
public class LoggingAspect {
   ...
}

回答1:


This is a common error when wiring up aspect classes. It means that your aspect class, in this case LoggingAspect has not been converted into an aspect which can be applied.

2 methods to weave your class into an aspect are using the AJDT Eclipse plugin or the Maven AspectJ compiler plugin.

There are 3 ways to weave aspects:

  • Compile-time weaving: compile either target source or aspect classes via dedicated aspectj compiler;
  • Post-compile weaving: inject aspect instructions to already compiled classes (Can be applied to JAR files)
  • Load-time weaving: inject aspect instructions to the byte code during class loading, i.e. load instrumented class instead of the 'raw' one;

Before an aspect class can be applied to a class it first need to be 'weaved' into an aspect.

An weaved aspect class will have these static methods added.




回答2:


AspectJ needs to weave both - your aspect class and the target class.

Weaving your aspect class

  • aspect class will get aspectOf() and hasAspect() methods injected.

Weaving the target class

  • adds calls to those methods.



回答3:


The problem is that your AspectJ weaving process isn't working. So you're calling the aspectOf method on an ordinary Java class and not an AspectJ class.

A simple way to test this:

  1. Weave with a tool like the Eclipse plugin AJDT
  2. Create a simple JUnit test with Spring.
  3. Finally make it work inside WAS.


来源:https://stackoverflow.com/questions/12929716/why-server-complaining-about-aspectof-is-missing

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