我正在尝试使用 Spring 5 学习 Spring AOP 编程。我正在浏览在线资料。
开始知道AOP是一个概念,类似于OOP;有了 AOP,OOP 变得更加强大。
现在,我正在尝试使用 Spring 框架版本 5 对 AOP 进行一些动手编码。
我将使用 maven 作为构建工具。
我不清楚我们必须在 pom.xml 中使用哪些依赖项,例如我们是否需要使用:spring-aop
、spring-aspects
, aspectj
等
任何人都可以指导我我们必须在 pom.xml 中添加哪些各种 maven 依赖项才能使用 maven 工具编写 Spring 5 AOP 程序?
提前致谢
最佳答案
这很简单,为了让 spring 与 AOP 一起工作,您需要 aspectjweaver 库存在于您的应用程序(版本 1.6.8 或更高版本)的类路径上。使用此依赖项来实现这一点
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.13</version>
</dependency>
正如他们在文档中提到的那样
To enable @AspectJ support with Java @Configuration add the @EnableAspectJAutoProxy annotation:
您可以找到更多信息 here
使某些东西与 AOP 一起工作的唯一 spring 依赖项是著名的 spring-context :
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
如果你想要一个工作示例,请查看我在 github 中的项目其中包含基于 spring 的基本 Maven AOP 示例
关于spring - 用于编写 Spring AOP 程序的 Maven 依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48467234/