SoFunction
Updated on 2025-04-12

Detailed explanation of the use of Spring-AOP-ProceedingJoinPoint

ProceedingJoinPoint Introduction

In Spring AOP, ProceedingJoinPoint is a subinterface of JoinPoint, which is specifically used for Around advice.

ProceedingJoinPoint contains the execution information of the notified method, and can also access the information and parameters of the notified method.

More flexible and finer surround notification logic can be achieved by using the ProceedingJoinPoint interface.

Get relevant information about the method of surrounding notification

The ProceedingJoinPoint interface provides the following commonly used methods:

()

This is the most important method in the ProceedingJoinPoint interface.

In the surrounding notification, calling the process() method will continue to execute the notified method.

If the process() method is not called in the surrounding notification, the notified method will not be executed.

@Around("execution(* .*.*(..))")
public Object aroundMethod(ProceedingJoinPoint joinPoint) throws Throwable {
    // Execute pre-logic    Object result = (); // Continue to execute the notification method    // Execute post-logic    return result;
}

Notice()The method may have a return value, and there may be many return value types, which can be directly set to Object type

()

Get the parameter array of notified methods

Object[] args = ();

()

Get the notified target object

Object target = ();

The main function of the ProceedingJoinPoint interface is to control the execution of the notified method in the surrounding notification, and can access the information and parameters of the notified method.

Developers can achieve more flexible and granular surround notification logic by using the ProceedingJoinPoint interface

Summarize

JoinPoint is used to obtain the information of the method, while ProceedingJoinPoint can also control the execution of the method, which makes it very useful in surround notifications.

In AOP practice, developers need to understand how these two interfaces are used and choose the appropriate interface according to specific needs to implement the function of cross-cutting the focus.

The above is personal experience. I hope you can give you a reference and I hope you can support me more.