Section 1. Spring AOP (XML)
1. Spring AOP
![](https://velog.velcdn.com/images%2Fcodren%2Fpost%2F257da655-ba13-4236-83de-bbb7d603c7cd%2Fimage.png)
3. Around Advice 구현
- MethodInterceptor 인터페이스 구현 (= 프록시 핸들러)
- invoke() 메서드를 오버라이딩 해야함
- proceed() 메서드를 이용하여 실제 객체의 메서드 호출 (= method.invoke)
![](https://velog.velcdn.com/images%2Fcodren%2Fpost%2F9b2b0e5e-3799-4c60-b2a5-c7c4645d28a2%2Fimage.png)
4. Before Advice 구현
- MethodBeforeAdvice 인터페이스 구현 ( = 프록시 핸들러)
- before() 메서드를 오버라이딩 해야함
- 실제 객체의 메서드를 호출할 필요 없음
![](https://velog.velcdn.com/images%2Fcodren%2Fpost%2Fbce5451f-778f-45c1-ad49-d24f1306dff2%2Fimage.png)
5. After Returning Advice 구현
- AfterReturningAdvice 인터페이스 구현 ( = 프록시 핸들러)
- afterReturning() 메서드를 오버라이딩 해야함
- Object returnValue - 메서드의 반환값
- Method method - 실제 호출되는 메서드
- Object[] args - 실제 호출되는 메서드의 인자값(들)
- Object target - 실제 객체
![](https://velog.velcdn.com/images%2Fcodren%2Fpost%2F8269beaf-969f-420f-b555-7246f66b424b%2Fimage.png)
6. After Throwing Advice 구현
- ThrowsAdvice 인터페이스 구현 ( = 프록시 핸들러)
- 오버라이딩할 메서드 X -> 수 많은 예외가 발생할 수 있으므로 특정한 것을 지정할 수 없음
![](https://velog.velcdn.com/images%2Fcodren%2Fpost%2Fe7ffe37e-9e59-4a76-9625-590050356cb5%2Fimage.png)
7. XML 설정
![](https://velog.velcdn.com/images%2Fcodren%2Fpost%2Fc0e99b97-b735-47f5-9227-855921013338%2Fimage.png)
① Target - 실제 객체
② MethodInterceptor - 부가 기능을 수행할 핸들러
③ Proxy - 부가 기능을 수행하고 실제 객체의 메서드를 호출
- proxy 객체에 setTarget() 메서드를 이용하여 실제 객체 매핑
- proxy 객체에 setInterceptorNames() 를 이용하여 핸들러 매핑
- list 태그는 참조(ref) 목록이므로 value로 지정하면 해당 id 값을 갖는 객체를 참조(ref)
- list 참조 목록에서 Before / Around 중에 상단에 있는 핸들러를 먼저 수행
- AfterReturning 이 Around 아래에 존재하면 실제 객체의 메서드가 반환된 후 수행되고, 위에 존재하면 Around Advice의 invoke 메서드가 반환된 후 수행됨
8. Main 부분
- XML 설정 파일에서 proxy 부분을 변경하면서 Spring AOP / DI 구현
![](https://velog.velcdn.com/images%2Fcodren%2Fpost%2Fe1f65734-db90-405e-b151-3a637e8741cb%2Fimage.png)
![](https://velog.velcdn.com/images%2Fcodren%2Fpost%2Fa83f4e88-4eb7-4f05-aa13-26ae437bda4d%2Fimage.png)