[英]Trying to implement answer (SO) about AOP spring to logging in REST API - some doubts
Firstly I tell that I am newbie at spring (on the whole, also AOP). 首先,我告诉我我是春季的新手(总的来说,也是AOP)。 At this moment I have working rest api.
目前,我有工作中的休息API。
I am trying to use this thread: 我正在尝试使用此线程:
Spring Boot - How to log all requests and responses with exceptions in single place? Spring Boot-如何在一个地方记录所有带有例外的请求和响应?
I am using spring boot and only annotations configuration. 我正在使用spring boot和仅注释配置。 I tried to follow this tutorial, however I have simple problems, I ask you for your help ( I tried to read more about AOP, but I would rather implement concrete example and then try to dig deeper ).
我尝试按照本教程进行操作,但是我遇到了一些简单的问题,请您提供帮助(我试图阅读有关AOP的更多信息,但是我希望实现具体示例,然后尝试进行更深入的了解)。
1. <aop:aspectj-autoproxy/>
Is it possible to express it using only annotations ? 1.
<aop:aspectj-autoproxy/>
是否可以仅使用注释来表达?
2. 2。
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
public @interface EnableLogging {
ActionType actionType();
}
Where this fragment should resiude ? 这个片段应该放在哪里? I tried to conclude and some place, but no effect.
我试图总结一下,但没有任何效果。
3. What about turning on Aspect ? 3. 打开Aspect怎么样? What does it mean ?
这是什么意思 ? For example, what does it mean this line:
例如,这行是什么意思:
@AfterReturning(pointcut = "execution(@co.xyz.aspect.EnableLogging * *(..)) && @annotation(enableLogging) && args(reqArg, reqArg1,..)", returning = "result")
Thanks in advance, answers to this question should help me get better aop. 在此先感谢您,这个问题的答案应该可以帮助我获得更好的AOP。
Haskell, why don't you ask your question in a comment under the answer you are referring to instead of in a new question? Haskell,为什么不在您所指的答案下的评论中问您的问题,而不是在新问题中问? Anyway, as for your questions:
无论如何,关于您的问题:
<aop:aspectj-autoproxy/>
by @EnableAspectJAutoProxy
, see Spring AOP manual, chapter 11.2.1 . <aop:aspectj-autoproxy/>
替换为@EnableAspectJAutoProxy
,请参见Spring AOP手册的第11.2.1章 。 @AfterReturning
: The advice method should always run after an intercepted method specified by the following pointcut has returned without an exception. @AfterReturning
:advice方法应始终在以下切入点指定的拦截方法返回后正常运行。 pointcut
: an expression describing where to weave in the subsequent advice code into your original code. pointcut
:一个表达式,描述将后续建议代码编织到原始代码中的位置。 execution(@co.xyz.aspect.EnableLogging * *(..))
: whenever a method annotated by @EnableLogging
is executed, no matter how many and which types of parameters and not matter which return type it has. execution(@co.xyz.aspect.EnableLogging * *(..))
:每当执行@EnableLogging
注释的方法时,无论有多少参数和哪种类型的参数,都不管其具有哪种返回类型。 @annotation(enableLogging)
binds the method annotation to an advice parameter so you can easily access it from the advice. @annotation(enableLogging)
将方法注释绑定到建议参数,因此您可以轻松地从建议中访问它。 args(reqArg, reqArg1,..)
binds the first two parameters of the intercepted method to advice parameters so you can easily access those, too. args(reqArg, reqArg1,..)
将拦截的方法的前两个参数绑定到通知参数,因此您也可以轻松地访问它们。 returning = "result"
binds the intercepted method's return value to another advice parameter so you can easily access that one from the advice as well. returning = "result"
将拦截的方法的返回值绑定到另一个通知参数,因此您也可以轻松地从通知中访问该参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.