Spring framework learning part 2 About AOP.
AOP stands for Aspect Oriented Programming. Aspect means "state", "face", etc.
Roughly speaking, conventions that are not directly related to business logic can be defined as common processing. For example, "Output the log immediately after the start and end of API processing".
When it comes to a system of a certain scale, log output and transactions become It may become essential, such as becoming a coding standard. However, even if it is a convention, if the same implementation is done every time, similar processing will be distributed, so there may be omissions in correction when changing specifications, and if you forget to write it in the first place I'm in trouble. In such a case, using AOP, log output just before the Controller method is called, etc. By calling common processing, log output is a class for log output, Controller leads to clarifying the role of Controller (higher cohesion). This kind of thing is called "cross-cutting concern separation".
concept | Contents |
---|---|
Aspect | The module itself that shows your interests Log output, exception handle, etc. |
Join Point | Points to carry out your concerns Immediately after the start of the controller, or when an exception is thrown |
Advice | Process executed at Join Point Around, Before, After, etc. |
Pointcut | Group of Join Points |
Weaving | The process of inserting Aspect at the appropriate point in the application code |
Target | Objects whose processing flow has been changed by AOP processing |
AOP | timing |
---|---|
Before | Before calling Target |
After Returning | When Target processing ends normally and control is returned to the caller |
After Throwing | When an exception occurs in Target processing and throws the exception to the caller |
After | Timing of both After Returning and After Throwing |
Around | Timing of both Before and After, that is, before and after calling Target |
that's all. good job.
[Thorough introduction to Spring Java application development with Spring Framework](https://www.amazon.co.jp/Spring%E5%BE%B9%E5%BA%95%E5%85%A5%E9%96%80- Spring-Framework% E3% 81% AB% E3% 82% 88% E3% 82% 8BJava% E3% 82% A2% E3% 83% 97% E3% 83% AA% E3% 82% B1% E3% 83% BC% E3% 82% B7% E3% 83% A7% E3% 83% B3% E9% 96% 8B% E7% 99% BA-% E6% A0% AA% E5% BC% 8F% E4% BC% 9A % E7% A4% BENTT% E3% 83% 87% E3% 83% BC% E3% 82% BF / dp / 4798142476 /)
Recommended Posts