我用 Spring AOP 写了一个非常简单的 Aspect。它有效,但我在理解真正发生的事情时遇到了一些问题。我不明白为什么我必须添加 aspectjweaver.jar? Spring-AOP 文档明确指出,只要我只使用 Spring-AOP,我就不需要 aspectj 编译器或编织器:
The AOP runtime is still pure Spring AOP though, and there is no dependency on the AspectJ compiler or weaver.
我的配置如下:
<aop:aspectj-autoproxy />
@Aspect
@Service
public class RemoteInvocationAspect {
@Before("execution(* at.test.mypackage.*.*(..))")
public void test() {
System.out.println("test");
}
...
我也尝试了 XML 配置,但没有改变任何东西。也许我可以放手,但我真的很想了解为什么要使用 aspectj-weaver?如果我不在 maven 中添加依赖项,我会得到 java.lang.ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException
最佳答案
我认为 Spring AOP 实现是重用了 aspectj-weaver 中的一些类。它仍然使用动态代理 - 不进行字节码修改。
以下comment来自 Spring 论坛可能会澄清。
Spring isn't using the AspectJ weaver in this case. It is simply reusing some of the classes from aspectjweaver.jar.
-Ramnivas
关于java - Spring AOP - 为什么我需要 aspectjweaver?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11446893/