프레임워크/Spring

[Spring] Spring AOP (Aspect-Oriented Programming)

pythaac 2022. 4. 19. 18:15

정의

  AOP는 핵심 관심사(core concerns)에서 공통 관심사(cross-cutting concerns)를 분리시키는 프로그래밍 기법으로, 공통 관심사를 추상화하고 캡슐화합니다.

 

공통 관심사 (Cross-cutting concerns)

  공통 관심사는 로깅, 검증, 트랜잭션, 시간측정과 같이, 서로 다른 메서드들에 공통적으로 반복되고, 모듈 자체에서 완전한 리팩토링할 수 없는 코드를 의미합니다.

 

AOP 주요 개념

  • Aspect
    - 모듈화한 공통 관심사
  • Join point
    - 프로그램 실행 중 한 시점, Spring AOP에서는 메서드 실행
  • pointcut
    - join point을 식별
  • Advice
    - pointcut에 의해 선택된 join point에 실행할 코드, cross-cutting concern 메서드
  • Target Object
    - advice가 적용될 객체들
    - Sping AOP에서는 런타임에 subclass가 생성되고, advice를 포함하여 target의 메서드를 오버라이딩
  • AOP proxy
    - Spring AOP는 JDK dynamic proxy를 사용하여 target class 및 advice 호출을 생성 -> AOP proxy class
    - CGLIB 프록시 사용 가능
  • Weaving
    - advice 객체 생성을 위해 aspect와 다른 어플리케이션/객체를 연결하는 과정

 

AOP Advice Type

  1. Before advice
    • join point 메서드 실행 전에 실행 (@Before)
  2. After (finally) advice
    • join point 메서드의 실행이 끝난 후 실행 (@After)
  3. Around advice
    • Target 메서드의 실행 전/후 등등 annotation이 advice 실행 위치를 지정

 

https://dev.to/anouar1611/spring-aop-introduction-and-concepts-of-aop-4oan

 

Spring AOP Introduction and Concepts of AOP

Introduction Spring Framework is developed on two core concepts – Dependency Injectio...

dev.to

https://seongmun-hong.github.io/spring/Spring-Aspect-Oriented-Programming(AOP)(1) 

 

Spring - AOP(1) - Aspect Oriented Programming

Aspect Oriented Programming (AOP) Native Approach 의 단점 아래와 같은 Bank Class가 존재한다고 생각해보자. Class...

Seongmun-Hong.github.io

https://stackoverflow.com/questions/242177/what-is-aspect-oriented-programming

 

What is aspect-oriented programming?

I understand object oriented programming, and have been writing OO programs for a long time. People seem to talk about aspect-oriented programming, but I've never really learned what it is or how ...

stackoverflow.com

https://docs.jboss.org/aop/1.0/aspect-framework/userguide/en/html/what.html

 

Chapter 1. What Is Aspect-Oriented Programming?

An aspect is a common feature that's typically scattered across methods, classes, object hierarchies, or even entire object models. It is behavior that looks and smells like it should have structure, but you can't find a way to express this structure in co

docs.jboss.org

https://en.wikipedia.org/wiki/Cross-cutting_concern

 

Cross-cutting concern - Wikipedia

In aspect-oriented software development, cross-cutting concerns are aspects of a program that affect other concerns. These concerns often cannot be cleanly decomposed from the rest of the system in both the design and implementation, and can result in eith

en.wikipedia.org

https://ko.wikipedia.org/wiki/%ED%9A%A1%EB%8B%A8_%EA%B4%80%EC%8B%AC%EC%82%AC

 

횡단 관심사 - 위키백과, 우리 모두의 백과사전

객체 지향 소프트웨어 개발에서 횡단 관심사 또는 크로스커팅 관심사(cross-cutting concerns)는 다른 관심사에 영향을 미치는 프로그램의 애스펙트이다. 이 관심사들은 디자인과 구현 면에서 시스템

ko.wikipedia.org