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

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

问题描述

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

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编译器或weaver。

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.

以下评论可能会澄清。


在这种情况下,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.

-Ramnivas

-Ramnivas

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

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