Bird
Raised Fist0
Spring Bootframework~5 mins

@Around advice for full control in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is the purpose of the @Around advice in Spring AOP?
The @Around advice allows you to run custom code before and after a method execution, giving full control over the method call, including the ability to modify arguments, control execution, and change the return value.
Click to reveal answer
intermediate
How do you access the method being advised inside an @Around advice?
You use the ProceedingJoinPoint parameter in the advice method. It provides the method signature, arguments, and lets you proceed with the original method call using proceed().
Click to reveal answer
intermediate
What happens if you do not call proceed() inside an @Around advice?
The original method will not be executed. This means you can completely skip the method or replace its execution with your own logic.
Click to reveal answer
intermediate
Can you modify the return value of a method using @Around advice? How?
Yes, by capturing the result of proceed() call, you can modify or replace it before returning it from the advice method.
Click to reveal answer
beginner
Show a simple example of an @Around advice method signature in Spring Boot.
public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable { // your code here Object result = joinPoint.proceed(); return result; }
Click to reveal answer
What parameter type must an @Around advice method accept to control method execution?
AProceedingJoinPoint
BJoinPoint
CMethodInvocation
DExecutionContext
What happens if you call proceed() multiple times inside an @Around advice?
AThe original method runs multiple times
BIt causes a compile error
COnly the first proceed() runs the method
DThe method runs once, but result is overwritten
Which of these can you NOT do inside an @Around advice?
AModify method arguments before execution
BSkip the method execution entirely
CChange the method's return value
DChange the method's signature
If you want to run code only after a method completes successfully, which advice is better than @Around?
A@After
B@AfterReturning
C@AfterThrowing
D@Before
What exception must your @Around advice method declare or handle?
ARuntimeException
BException
CThrowable
DNo exception needed
Explain how @Around advice gives you full control over a method execution in Spring Boot.
Think about what you can do before and after calling the original method.
You got /5 concepts.
    Describe a scenario where using @Around advice is better than @Before or @After advice.
    Consider when you want full control, not just before or after.
    You got /4 concepts.

      Practice

      (1/5)
      1. What is the main purpose of using @Around advice in Spring AOP?
      easy
      A. To run code before and after a method, controlling its execution fully
      B. To only run code after a method finishes
      C. To replace the method with a new implementation without calling the original
      D. To log method parameters without affecting execution

      Solution

      1. Step 1: Understand the role of @Around advice

        @Around advice wraps a method, allowing code to run before and after the method execution.
      2. Step 2: Compare options with this behavior

        Only To run code before and after a method, controlling its execution fully describes full control before and after the method, matching @Around's purpose.
      3. Final Answer:

        To run code before and after a method, controlling its execution fully -> Option A
      4. Quick Check:

        @Around advice = full control before and after method [OK]
      Hint: Remember @Around wraps method execution fully [OK]
      Common Mistakes:
      • Thinking @Around only runs after method
      • Confusing @Around with @After or @Before
      • Forgetting @Around can modify inputs and outputs
      2. Which of the following is the correct way to proceed with the original method inside an @Around advice method?
      easy
      A. return joinPoint.proceed();
      B. joinPoint.execute();
      C. proceed(joinPoint);
      D. joinPoint.run();

      Solution

      1. Step 1: Recall the method to call original execution

        In @Around advice, the original method is executed by calling joinPoint.proceed().
      2. Step 2: Match the correct syntax

        Only return joinPoint.proceed(); uses the correct method name and syntax to proceed.
      3. Final Answer:

        return joinPoint.proceed(); -> Option A
      4. Quick Check:

        Call original method with joinPoint.proceed() [OK]
      Hint: Use joinPoint.proceed() to run original method [OK]
      Common Mistakes:
      • Using incorrect method names like execute() or run()
      • Forgetting to return the result of proceed()
      • Calling proceed() without parentheses
      3. Given the following @Around advice code, what will be printed when someMethod() returns "Hello"?
      @Around("execution(* someMethod())")
      public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
          System.out.println("Before");
          Object result = joinPoint.proceed();
          System.out.println("After");
          return result + " World";
      }
      medium
      A. Before Hello After World
      B. Hello Before After World
      C. Before After Hello
      D. Before After Hello World

      Solution

      1. Step 1: Trace the advice execution order

        The advice prints "Before", then calls the original method which returns "Hello", then prints "After".
      2. Step 2: Understand the returned value

        The advice returns the original result plus " World", so the final returned string is "Hello World".
      3. Final Answer:

        Before After Hello World -> Option D
      4. Quick Check:

        Prints before and after, returns modified result [OK]
      Hint: Remember @Around runs code before and after proceed() [OK]
      Common Mistakes:
      • Assuming original method output is unchanged
      • Mixing print order with return value
      • Forgetting to add " World" to result
      4. Identify the error in this @Around advice method:
      @Around("execution(* someMethod())")
      public Object aroundAdvice(ProceedingJoinPoint joinPoint) {
          System.out.println("Start");
          Object result = joinPoint.proceed();
          System.out.println("End");
          return result;
      }
      medium
      A. Incorrect annotation syntax
      B. Missing throws Throwable declaration in method signature
      C. Should call joinPoint.execute() instead of proceed()
      D. Cannot return Object type from advice

      Solution

      1. Step 1: Check method signature requirements

        joinPoint.proceed() throws Throwable, so the advice method must declare throws Throwable or handle it.
      2. Step 2: Identify missing throws declaration

        The method lacks "throws Throwable", causing a compile error.
      3. Final Answer:

        Missing throws Throwable declaration in method signature -> Option B
      4. Quick Check:

        proceed() throws Throwable, must declare it [OK]
      Hint: Add throws Throwable when calling joinPoint.proceed() [OK]
      Common Mistakes:
      • Ignoring checked exceptions from proceed()
      • Using wrong method name instead of proceed()
      • Not matching annotation syntax
      5. You want to create an @Around advice that modifies the input argument of a method before execution and changes the returned result after execution. Which approach correctly achieves this?
      hard
      A. Modify the method parameters directly without using proceed, then return null
      B. Call joinPoint.proceed() without arguments, then ignore the result and return a new value
      C. Modify the argument array via joinPoint.getArgs(), then call joinPoint.proceed(modifiedArgs), and finally modify the returned result before returning
      D. Use joinPoint.proceed() and modify the result, but cannot change input arguments

      Solution

      1. Step 1: Understand argument modification in @Around advice

        You can get and modify method arguments using joinPoint.getArgs() and pass them to proceed() to change inputs.
      2. Step 2: Modify the returned result after proceed()

        After calling proceed with modified arguments, you can change the returned value before returning it.
      3. Final Answer:

        Modify the argument array via joinPoint.getArgs(), then call joinPoint.proceed(modifiedArgs), and finally modify the returned result before returning -> Option C
      4. Quick Check:

        Change inputs with proceed(args), then modify output [OK]
      Hint: Use proceed(modifiedArgs) to change inputs, then modify output [OK]
      Common Mistakes:
      • Calling proceed() without modified arguments when inputs need change
      • Trying to change parameters directly without proceed()
      • Ignoring returned result modification
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard