简体   繁体   English

具有aspectj注释的Spring AOP

[英]Spring AOP with aspectj annotation

I am sorry that my question is little bit silly, but i need to understand, i am trying to write a logger based on spring aop, i know that there are several realizations, like xml based schema or aspectj annotations, in case i prefer an aspectj annotations does it means that i dont need a xml configuration file at all? 我很抱歉我的问题有点傻,但我需要理解,我正在尝试编写一个基于spring aop的记录器,我知道有几种实现,如基于xml的架构或aspectj注释,以防我更喜欢aspectj annotations是否意味着我根本不需要xml配置文件? I have read many tutorials and examples ones were with xml while another ones were not, now i have messed up with it, can some one give a good explanation for a newbie or mare a ref? 我已经阅读了许多教程和示例,其中一些是xml,而另一些则没有,现在我搞砸了,有人可以给新手或母马一个很好的解释吗? Thank you. 谢谢。

If you're referring to using AspectJ annotations with Spring AOP then you will need a bit of XML configuration on the Spring side but can mostly manage the aspects with annotations. 如果您指的是在Spring AOP中使用AspectJ注释,那么您需要在Spring方面进行一些XML配置,但主要可以使用注释来管理方面。 The XML configuration you will need is to at least: 您需要的XML配置至少是:

  1. Turn on AOP auto-proxy with <aop:aspectj-autoproxy/> 使用<aop:aspectj-autoproxy/>打开AOP自动代理
  2. Use Spring component scan to find your annotated aspects with <context:component-scan base-package="package.of.some.aspect" /> 使用Spring组件扫描通过<context:component-scan base-package="package.of.some.aspect" />查找带注释的方面

An example can be found here 这里可以找到一个例子

You should note there are several limitations with how AspectJ annotations apply with respect to Spring AOP, which can be found in the Spring documentation 您应该注意到AspectJ注释如何应用于Spring AOP有一些限制,可以在Spring文档中找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM