【发布时间】:2013-02-16 10:00:17
【问题描述】:
我正在学习 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 安德烈亚
【问题讨论】:
标签: java spring maven spring-mvc cglib