- Building Microservices with Spring
- Dinesh Rajput Rajesh R V
- 331字
- 2021-07-02 14:54:13
Advice
An internet plan is used for calculating the bill according to data usage in MB or GB by the internet company. The internet company has a list of customers, also and they also company calculates the internet bill for them. So calculating bills and sending it to the customers is a core job for the internet company but not for customers. Likewise, each aspect has its own main job and also has a purpose for doing this job. The job of an aspect is known as advice in the AOP.
As you know now, advice is a job, aspect will perform this job, so there are some questions that come to in mind, when to perform this job and what will be in this job. Will this job be performed before a business method is invoked? Or will it be performed after the business method is invoked? Or will it be performed both before and after method invocation? Or it will be performed when business method throws an exception. Sometime this business method is also called the advised method. Let's see the following five kinds of advises used by Spring aspects:
- Before: Advice's job executes before the advised method is invoked.
- After: Advice's job executes after the advised method completes regardless of whether an exception has been thrown by the target or not.
- After-returning: Advice's job executes after the advised method successfully completes. For example, if a business method returns without throwing an exception.
- After-throwing: Advice's job executes if the advised method exits by throwing an exception.
- Around: This is one of the most powerful advice of Spring AOP, this advice surrounds the advised method, providing some advice's job before and after the advised method is invoked.
In short, advice's job code to be executed at each selected point that is, Join Point, let's look into another term of AOP.