我正在学习本教程的 Spring Framework 中的 AOP:http ://www.tutorialspoint.com/spring/schema_based_aop_appoach.htm
与上一个教程不同,我没有手动添加所需的 jars 文件,而是使用 Maven。
最初我在我的 pom.xml 中添加了这个依赖项(除了那些与 spring-core、spring-bean、spring-context、spring-context-support Spring 模块相关的)
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
但是,以这种方式不起作用并引发以下异常:
引起:java.lang.ClassNotFoundException:org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException
在线阅读我找到了解决方案:我必须在我的 pom.xml 中添加这两个依赖项:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
所以现在我有两个疑问:
如果我还没有org.springframework.spring-aop,为什么我必须添加这个org.aspectj.aspectjtools依赖项?(另外...我注意到我可以删除org.springframework.spring-aop,这个没用)它们有什么区别?
为什么我必须添加cglib依赖项?我知道当我使用 @Configuration 和 @Bean 之类的注释时我必须使用 cglib ......但是为什么在这种情况下我需要这个没有这些注释的依赖项?
Tnx安德烈亚