Aspect Oriented Programming

// the “extra stuff” is auto handled around it

SpringBoot Architecture

Client
  ↓
Filter
  ↓
DispatcherServlet
  ↓
Interceptor        ←  (Web layer)
  ↓
Controller
  ↓
AOP Proxy  
(@Before/@Around)  ←  (Bean layer)
  ↓
Service            →  Exception thrown
  ↓                        ↓
Repository            AOP (@AfterThrowing runs if exists)
  ↓                        ↓
AOP                   Controller
(@After /                  ↓          
@AfterReturning)      HandlerExceptionResolver               
  ↓                        ↓
Interceptor           @RestControllerAdvice
(postHandle)               ↓
  ↓                   Return JSON error
Interceptor 
(afterCompletion)                   

How AOP works:

Spring Boot starts
     ↓
Bean created
     ↓
@Aspect detected
     ↓
Registers AnnotationAwareAspectJAutoProxyCreator
     ↓
1. bean matches pointcut 
2. Spring wraps it with proxy
Spring creates a PROXY for the bean
     ↓
Client calls proxy
     ↓
Proxy executes advice
     ↓
Proxy calls real method

Interceptor (diff from AOP)