AOP 사용방법
applicationContext.xml(루트 컨테이너)에 의존성 주입
<의존성 주입 코드>
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
주요 어노테이션
- @Aspect : 클래스가 하나 이상의 관점(핵심관심+공통관심)을 정의
<aop:aspect></aop:aspect>
- @Pointcut("excution(* 핵심관심(..))") : 특정 포인트컷(핵심관심)을 정의
<aop:pointcut id="포인트컷 명칭" expression="execution(* 핵심관심(..))"/>
- @Before : 지정한 포인트컷에서 메서드가 실행되기 전에 실행
<aop:before method="메서드명" pointcut-ref="포인트컷 명칭"></aop:before>
- @After : 메서드가 실행 후에 실행(정상실행, 예외실행 전부)
<aop:after method="메서드명" pointcut-ref="포인트컷 명칭"></aop:after>
- @AfterReturning : 메서드가 정상적으로 실행된 후에 실행
<aop:after-returning method="메서드명" pointcut-ref="포인트컷 명칭"></aop:after-returning>
- @AfterThrowing : 메서드가 예외를 던졌을 때 실행
<aop:after-throwing method="메서드명" pointcut-ref="포인트컷 명칭"></aop:after-throwing>
- @Around : 메서드 실행 전후에 모두 실행
<aop:around method="메서드명" pointcut-ref="포인트컷 명칭"></aop:around>
2024.10.17
'Spring' 카테고리의 다른 글
| [Spring] 12. 트랜잭션 (0) | 2024.10.22 |
|---|---|
| [Spring] 11. DAO 고도화(템플릿 패턴) (0) | 2024.10.22 |
| [Spring] 10. AOP(관점 지향 프로그래밍) (0) | 2024.10.16 |
| [Spring] 09. Spring 비동기 처리 (0) | 2024.10.15 |
| [Spring] 08. 2-Layerd 아키텍처 구조 (0) | 2024.10.15 |