[JAVA] Overview of Spring AOP

Spring framework learning part 2 About AOP.

AOP overview

What is AOP

AOP stands for Aspect Oriented Programming. Aspect means "state", "face", etc.

What you can do with AOP

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".

Why use AOP

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".

AOP concept

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

Advice available in Spring

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.

Reference book

[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

Overview of Spring AOP
About binding of Spring AOP Annotation
About Spring AOP
About spring AOP
[Java] Overview of Java
[Spring] Pitfalls of BeanUtils.copyProperties
About DI of Spring ①
About Spring AOP Pointcut
About DI of Spring ②
Overview of Docker and containers
Introduction to Spring Boot ② ~ AOP ~
[Java] Spring AOP execution order
How to unit test Spring AOP
Memorandum of understanding when Spring Boot 1.5.10 → Spring Boot 2.0.0
Spring Framework 5.0 Summary of major changes
spring framework Simple study memo (2): AOP
Going out of message (Spring boot)
[Spring Boot] Role of each class
Spring AOP for the first time
Filter the result of BindingResult [Spring]
About the initial display of Spring Framework
Summary of going to JJUG CCC 2019 Spring
Features of spring framework for java developers
[Java] [Spring] Test the behavior of the logger