maven dependencies for writing Spring AOP programs?

こ雲淡風輕ζ 提交于 2020-03-03 13:45:12

问题


I am trying to learn Spring AOP programming using Spring 5. I am going through online materials.

I came to know that AOP is a concept, similar to OOP; and with AOP,OOPs becomes more powerful.

Now, I am trying to do some hands-on coding for AOP with Spring framework, version 5.

I am going to use maven as the build tool.

I am not clear on what are the various dependencies that we have to use in pom.xml, for example do we need to use: spring-aop , spring-aspects, aspectjetc.

Can anyone guide me what are the various maven dependencies that we have to add in pom.xml to be able to write using maven tool, Spring 5 AOP programs?

Thanks in advance


回答1:


Its very simple, in order to work spring With AOP, You need aspectjweaver Library existe on the classpath of your application (version 1.6.8 or later).use this dependency to achieve that

<dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.8.13</version>
</dependency>

As they mention in docs

To enable @AspectJ support with Java @Configuration add the @EnableAspectJAutoProxy annotation:

You can find more info here

The only spring dependency to make something work with AOP is the famous spring-context :

 <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.0.2.RELEASE</version>
</dependency>

If you want a working example check my project in github which contains basic Maven AOP example based on spring



来源:https://stackoverflow.com/questions/48467234/maven-dependencies-for-writing-spring-aop-programs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!