0 votes
in Spring by
What is an advice? Explain its types in spring.

1 Answer

0 votes
by

An advice is the implementation of cross-cutting concern can be applied on other modules of the spring application. Advices are of mainly 5 types :

Before :

This advice executes before a join point, but it does not have the ability to prevent execution flow proceeding to the join point (unless it throws an exception).

To use this, use @Before annotation.

AfterReturning :

This advice is to be executed after a join point completes normally i.e if a method returns without throwing an exception.

To use this, use @AfterReturning annotation.

AfterThrowing :

This advice is to be executed if a method exits by throwing an exception.

To use this, use @AfterThrowing annotation.

After :

This advice is to be executed regardless of the means by which a join point exits (normal return or exception encounter).

To use this, use @After annotation.

Around :

This is the most powerful advice surrounds a join point such as a method invocation.

To use this, use @Around annotation.

Related questions

0 votes
asked Apr 4, 2021 in Spring by Robindeniel
0 votes
asked Apr 4, 2021 in Spring by Robindeniel
...