스프링 5 레시피/스프링 코어
AOP + POJO
휘휘o
2021. 4. 14. 10:22
Introduction을 이용해 POJO에 기능 더하기
introduction 이란?
- AOP 어드바이스의 특별한 타입
- 객체가 어떤 인터페이스의 구현 클래스를 공급받아 동적으로 인터페이스를 구현하는 기술
- 객체가 런타임에 구현 클래스를 상속하는 것처럼 보임
- 다중 상속 가능
동작 원리 : introduction은 동적 프록시에 여러 인터페이스를 지정해 작동
사용법
@Aspect
@Component
public class Exam {
@DeclareParents(
value = "패키지명.클래스명",
defaultImpl = 구현클래스명.class
)
public Interface1 interface1;
@DeclareParents(
value = "패키지명.클래스명",
defaultImpl = 구현클래스명.class
)
public Interface2 interface2;
}
- 위와 같이 introduction을 만들고 사용할 클래스에서 빈 객체를 생성해 사용할 수 있다.