Spring AOP - 为什么我需要aspectjweaver? [英] Spring AOP - why do i need aspectjweaver?

查看:42
本文介绍了Spring AOP - 为什么我需要aspectjweaver?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 Spring AOP 写了一个非常简单的 Aspect.它有效,但我在理解真正发生的事情时遇到了一些问题.我不明白为什么我必须添加aspectjweaver.jar?Spring-AOP 文档明确指出,只要我只使用 Spring-AOP,我就不需要 aspectj 编译器或编织器:

i wrote a very simple Aspect with Spring AOP. It works, but i have some problems understanding what is really going on. I don't understand why i have to add the aspectjweaver.jar? The Spring-AOP documentation clearly states that i don't need aspectj compiler or weaver as long as i just use Spring-AOP:

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

I also tried XML configuration, didn't change anything though. Maybe i could just let it go, but i really would like to understand why aspectj-weaver is used? If i don't add the dependency in maven i get java.lang.ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException

推荐答案

Spring AOP 实现我认为是重用了 aspectj-weaver 中的一些类.它仍然使用动态代理 - 不进行字节码修改.

Spring AOP implementation I think is reusing some classes from the aspectj-weaver. It still uses dynamic proxies - doesn't do byte code modification.

以下评论来自春季论坛的可能会澄清.

The following comment from the spring forum might clarify.

在这种情况下,Spring 没有使用 AspectJ 编织器.简直就是重用了 aspectjweaver.jar 中的一些类.

Spring isn't using the AspectJ weaver in this case. It is simply reusing some of the classes from aspectjweaver.jar.

-拉姆尼瓦斯

这篇关于Spring AOP - 为什么我需要aspectjweaver?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆