본문 바로가기

Java/Spring

Spring AOP: AOP Concepts 1

이 글은 Spring Framework 5.2.8 버전 Core Technologies의 AOP 문서에 기반하여 작성되었습니다.

 

AOP에서 중점적으로 사용되는 용어들에 대한 정의입니다. 이 용어들은 Spring에만 국한된 것은 아니며, 용어들의 어감이 직관적으로 느껴지지 않을 수 있습니다. 하지만 Spring을 위한 새로운 용어를 사용하는 것은 더 큰 혼란을 가져올 수 있을 것입니다.

 

Aspect

앞서 언급된 Aspect는 여러 Class들을 관통하는 관심사를 모듈화한 것입니다. Java 어플리케이션에서의 Transaction 관리가 횡단 관심사의 좋은 예시입니다. Spring AOP에서 Aspect는 스키마 기반 접근, 혹은 애너테이션 기반한 접근법으로 사용이 가능하며, 특히 @AspectJ 스타일에 해당하는 @Aspect 애너테이션으로 사용이 가능합니다.

 

Join point

Join point는 method의 실행 혹은 exception 핸들링 시점 등의 프로그램 실행의 시점을 가르킵니다. Spring AOP에서의 Join point는 항상 method의 실행 시점입니다.

 

Advice

특정 Join point에서 Aspect에 의해 취해진 액션을 의미합니다. Advice는 'before', 'after', 'around' 등의 다양한 형태가 존재합니다. Spring을 포함한 많은 AOP 프레임워크는 interceptor로서 Advice를 모델링하며, Join point 주변의 interceptor들의 연결을 지원합니다. (Many AOP frameworks, including Spring, model an advice as an interceptor and maintain a chain of interceptors around the join point.)

 

Pointcut

Pointcut은 Join point가 어느 시점을 나타내는지 선언한 것입니다. Advice는 Pointcut의 표현과 결합하여 Join point에서 작동하게 됩니다. 예를 든다면 Pointcut에서 특정 이름을 가진 method를 지정한 경우, 해당 method의 실행 전후로 Advice가 실행되는 것이 이에 해당합니다. Pointcut의 표현과 일치하는 시점이 Join point라는 것이 AOP의 중심이라고 할 수 있으며, Spring에서는 기본적으로 AspectJ Pointcut의 표현법을 따릅니다.

 

Introduction

Declaring additional methods or fields on behalf of a type. Spring AOP lets you introduce new interfaces (and a corresponding implementation) to any advised object. For example, you could use an introduction to make a bean implement an IsModified interface, to simplify caching. (An introduction is known as an inter-type declaration in the AspectJ community.)

 

Target object

Target object는 하나 혹은 그 이상의 Aspect에 의해 Advice되는 객체를 의미합니다. 그렇기 때문에 Adviced object로도 얘기할 수 있을 것입니다. Spring AOP에서는 runtime 시점의 proxy를 사용하여 구현되기 때문에, 이 객체는 항상 proxy된 객체가 될 것입니다.

 

AOP proxy

Aspect를 위하여 AOP 프레임워크에 의해 생성된 객체입니다. Spring 프레임워크에서의 AOP proxy는 JDK dynamic proxy나 CGLIB proxy로 생성됩니다.

 

Weaving

Aspect들을 애플리케이션 유형 또는 객체들과 연결하여 실제적인 Advised object를 생성하는 것을 의미합니다. 이는 AspectJ 컴파일러 등을 이용하여 컴파일 시점에서 이뤄지기도 하며, 로드 시점이나 런타임 시점에서 이뤄지기도 합니다. Spring AOP는 다른 Java AOP 프레임워크들과 같이 런타임 시점에 Weaving을 수행합니다.

 

AOP Concepts

https://docs.spring.io/spring/docs/5.2.8.RELEASE/spring-framework-reference/core.html#aop-introduction-defn

'Java > Spring' 카테고리의 다른 글

Spring AOP: AOP Concepts 2  (0) 2020.07.30
Spring AOP: Aspect Oriented Programming with Spring  (0) 2020.07.15
Custom Constraint  (0) 2020.07.07
@Transactional Attribute  (0) 2020.06.29
Spring StopWatch  (0) 2020.04.28