0

Firstly I tell that I am newbie at spring (on the whole, also AOP). At this moment I have working rest api.
I am trying to use this thread:

Spring Boot - How to log all requests and responses with exceptions in single place?

I am using spring boot and only annotations configuration. 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 ).
1. <aop:aspectj-autoproxy/> Is it possible to express it using only annotations ?
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 ? 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.

Community
  • 1
  • 1

1 Answers1

0

Haskell, why don't you ask your question in a comment under the answer you are referring to instead of in a new question? Anyway, as for your questions:

  1. Yes, you can replace <aop:aspectj-autoproxy/> by @EnableAspectJAutoProxy, see Spring AOP manual, chapter 11.2.1.
  2. This "fragment" is not a fragment but a full Java annotation declaration. Maybe you want to learn some Java basics before trying complicated stuff like Spring AOP?
  3. Please read the full Spring AOP chapter in order to get a basic understanding of Spring AOP. As for the AspectJ language as such or the meaning of terms such as joinpoint, pointcut, advice, you should read an AspectJ primer. This code snippet expresses the following:
    • @AfterReturning: The advice method should always run after an intercepted method specified by the following pointcut has returned without an exception.
    • pointcut: an expression describing where to weave in the subsequent advice code into your original code.
    • 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.
    • @annotation(enableLogging) binds the method annotation to an advice parameter so you can easily access it from the advice.
    • args(reqArg, reqArg1,..) binds the first two parameters of the intercepted method to advice parameters so you can easily access those, too.
    • 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.
Community
  • 1
  • 1
kriegaex
  • 63,017
  • 15
  • 111
  • 202