Spring Certified Professional 2023 · Free Practice Question Easy

Question 24

Which pointcut expression in Spring AOP matches join points for method execution?

  • A

    args

  • B

    within

  • C

    target

  • D

    execution

Reveal correct answer

Correct answer: D

Explanation

Spring AOP provides different types of Pointcut expressions to specify which methods or join points should be advised. Some of the commonly used pointcut expressions are:

  1. Execution - matches join points for method execution.

  2. Within - matches join points within certain types or packages.

  3. This - matches join points where the bean reference is an instance of a given type.

  4. Target - matches join points where the target object is an instance of a given type.

  5. Args - matches join points where the arguments to the method being executed match a given type or expression.

  6. Annotation - matches join points where the subject has the given annotation.

These pointcut expressions can be used alone or in combination to create more complex pointcut expressions.


Here's an example of the execution pointcut expression in Spring AOP:

In this example, we define an aspect named MyAspect that intercepts calls to the getUser method in the UserService class. The @Before annotation indicates that the method should be executed before the target method is invoked, and the execution pointcut expression specifies the exact method signature to intercept.


https://docs.spring.io/spring-framework/docs/2.0.x/reference/aop.html#aop-pointcuts

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need