java - Spring AOP - 为什么我需要 aspectjweaver?

标签 java spring aop aspectj spring-aop

我用 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/

相关文章:

java - 使用RMI以本地模式连接JMX(无端口)

java - 使用java创建正则表达式以从字符串中提取4位数字

java - FileServlet(BalusC 的解决方案)在 IE 中不显示保存对话框

java - 如何在 Swagger 中描述多态端点?

java - IDEA 无法在插件依赖项中找到 AspectJ 编译器 .jar

java - Android 应用程序 Web View 后退按钮

java - Wicket 附加到现有的 Spring 上下文

java - 我不能在 Spring Autowiring 存储库

design-patterns - 在通用存储库上使用Decorator模式实现的AOP

Spring AOP 匹配通配符严格,但是找不到元素 'aop:config'的声明