1. AOP 의존성 등록

<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.4</version>
</dependency>

 

 

 

 

 

2. 타겟 객체 생성 (핵심 기능 구현한 빈)

 

 

 

3. aspect 객체 생성 (부가 기능 구현한 빈)

가. @Aspect 어노테이션 지정

 

 

나. pointcut 지정: 어떤 핵심기능의 메서드인지 알려주는 기능

      https://docs.spring.io/spring-framework/docs/5.2.25.RELEASE/spring-framework-reference/core.html#aop-pointcuts-examples

 

Core Technologies

In the preceding scenario, using @Autowired works well and provides the desired modularity, but determining exactly where the autowired bean definitions are declared is still somewhat ambiguous. For example, as a developer looking at ServiceConfig, how do

docs.spring.io

@Pointcut("execution(public String sayEcho())") 
public void xxx( ){
    // 아무 구현 안함
 }

 

다. advice 지정된 메서드

@Before("xxx( )")
public void method2( ) {
     // 부가기능 구현
}

 

 

 

 

4. target과 aspect 빈 모두 xml에 등록

 

 

 

 

5. @Aspect 어노테이션 활성화

 

 

6. TestMain 작성

 

 


 

결과

 

 

 


 

 

 

advice + pointcut 같이 표현

xoo | 수진