티스토리 뷰
Spring/Spring AOP
Spring : AOP with Java Config - @Pointcut annotation
Korean Eagle 2020. 5. 12. 16:01728x90
0. 이 포스트는 Spring : AOP with Java Config 시리즈의 연속이다.
1. @Pointcut annotation의 목적은 하나의 point cut expression을 여러 advice 메소드에서 사용하기 위한 것이다.
1-1 즉 여러 개의 advice 메소드를 동일한 조건에서 사용할 경우에 중복을 제거하기 위함이다.
1-2 장점을 나열해 보면 쉬운 재사용, 한 곳에서 수정할 수 있음, 여러 포인트 컷의 공유와 조합이 편리함
2. @Pointcut 메소드를 정의한다.
2-1 아래의 코드의 forDAOPackage메소드는 @Pointcut으로 수식되어 있다.
2-2 단순히 point cut expression의 중복을 줄이기 위해서 사용하였다.
2-3 아래 소스는 예전의 소스와 동일하다.
2-4 결과는 이전과 동일하다.
@Aspect
@Component
public class LoggingAspect {
// @Before(value = "execution(public void addAccount())")
// @Before(value = "execution(public void add*())")
// @Before(value="execution(boolean add*())")
// @Before(value="execution(* add*())")
// @Before(value="execution(* add*(pe.pilseong.spring_aop_review.Account))")
// @Before(value="execution(* add*(pe.pilseong.spring_aop_review.Account, ..))")
// @Before(value="execution(* add*(..))")
// @Before("execution(* pe.pilseong.spring_aop_review.dao.*.*(..))")
// public void beforeAddAccountAdvice() {
// System.out.println("\nExecuting @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)");
// }
@Pointcut(value = "execution(* pe.pilseong.spring_aop_review.dao.*.*(..))")
public void forDAOPackage() {}
@Before(value = "forDAOPackage()")
public void beforeAddAccountAdvice() {
System.out.println("\nExecuting @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)");
}
}
// 실행 클래스
public class App {
public static void main(String[] args) {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(JavaConfig.class);
AccountDAO accountDAO = context.getBean("accountDAO", AccountDAO.class);
accountDAO.addAccount();
Account account = new Account();
accountDAO.addAccount(account);
accountDAO.addAccount(account, true);
MembershipDAO membershipDAO = context.getBean("membershipDAO", MembershipDAO.class);
membershipDAO.addAccount();
membershipDAO.addGoodAccount();
membershipDAO.membership();
context.close();
}
}
// 실행 결과
Executing @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)
in beforeAddAccountAdvice
class pe.pilseong.spring_aop_review.dao.AccountDAO: with Account Parameter. Doing my DB work: Adding an account
Executing @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)
in beforeAddAccountAdvice
class pe.pilseong.spring_aop_review.dao.AccountDAO: with Account, boolean Parameter. Doing my DB work: Adding an account
Executing @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)
in beforeAddAccountAdvice
class pe.pilseong.spring_aop_review.dao.MembershipDAO: Doing my DB work: Adding an account
Executing @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)
in beforeAddAccountAdvice
class pe.pilseong.spring_aop_review.dao.MembershipDAO: Doing my DB work: Adding a good account
Executing @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)
in beforeAddAccountAdvice
class pe.pilseong.spring_aop_review.dao.MembershipDAO: Doing my DB work: membership method is doing something
3. 동일한 @Pointcut을 사용하는 다른 메소드를 Advice에서 정의한다.
3-1 패키지에 포함된 메소드가 호출될 때 두 advice메소드가 차례로 실행된다.
@Aspect
@Component
public class LoggingAspect {
@Pointcut(value = "execution(* pe.pilseong.spring_aop_review.dao.*.*(..))")
public void forDAOPackage() {}
@Before(value = "forDAOPackage()")
public void beforeAddAccountAdvice() {
System.out.println("\nExecuting in beforeAddAccountAdvice @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)");
}
@Before(value = "forDAOPackage()")
public void performApiAnalytics() {
System.out.println("\nExecuting in performApiAnalytics @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)");
}
}
// 실행 결과
Executing in beforeAddAccountAdvice @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)
Executing in performApiAnalytics @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)
class pe.pilseong.spring_aop_review.dao.AccountDAO: with No Parameter Doing my DB work: Adding an account
Executing in beforeAddAccountAdvice @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)
Executing in performApiAnalytics @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)
class pe.pilseong.spring_aop_review.dao.AccountDAO: with Account Parameter. Doing my DB work: Adding an account
Executing in beforeAddAccountAdvice @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)
Executing in performApiAnalytics @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)
class pe.pilseong.spring_aop_review.dao.AccountDAO: with Account, boolean Parameter. Doing my DB work: Adding an account
Executing in beforeAddAccountAdvice @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)
Executing in performApiAnalytics @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)
class pe.pilseong.spring_aop_review.dao.MembershipDAO: Doing my DB work: Adding an account
Executing in beforeAddAccountAdvice @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)
Executing in performApiAnalytics @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)
class pe.pilseong.spring_aop_review.dao.MembershipDAO: Doing my DB work: Adding a good account
Executing in beforeAddAccountAdvice @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)
Executing in performApiAnalytics @Before advice on pe.pilseong.spring_aop_review.dao.*.*(..)
class pe.pilseong.spring_aop_review.dao.MembershipDAO: Doing my DB work: membership method is doing something
728x90
'Spring > Spring AOP' 카테고리의 다른 글
Spring : AOP with Java Config - Aspect 실행 순서 설정 (0) | 2020.05.13 |
---|---|
Spring : AOP with Java Config - Combining Pointcut Expression (0) | 2020.05.12 |
Spring : AOP with Java Config - Parameter Pattern Wildcards (0) | 2020.05.12 |
Spring : AOP with Java Config - PointCut Expression (0) | 2020.05.12 |
Spring : AOP with Java Config - 설정하기와 @Before advice (0) | 2020.05.11 |
댓글
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
- 도커 개발환경 참고
- AWS ARN 구조
- Immuability에 관한 설명
- 자바스크립트 멀티 비동기 함수 호출 참고
- WSDL 참고
- SOAP 컨슈머 참고
- MySql dump 사용법
- AWS Lambda with Addon
- NFC 드라이버 linux 설치
- electron IPC
- mifare classic 강의
- go module 관련 상세한 정보
- C 메모리 찍어보기
- C++ Addon 마이그레이션
- JAX WS Header 관련 stackoverflow
- SOAP Custom Header 설정 참고
- SOAP Custom Header
- SOAP BindingProvider
- dispatcher 사용하여 설정
- vagrant kvm으로 사용하기
- git fork, pull request to the …
- vagrant libvirt bridge network
- python, js의 async, await의 차이
- go JSON struct 생성
- Netflix Kinesis 활용 분석
- docker credential problem
- private subnet에서 outbound IP 확…
- 안드로이드 coroutine
- kotlin with, apply, also 등
- 안드로이드 초기로딩이 안되는 경우
- navigation 데이터 보내기
- 레이스 컨디션 navController
- raylib
TAG
- 스프링부트
- 설정하기
- hibernate
- crud
- one-to-one
- 설정
- RestTemplate
- MYSQL
- login
- 매핑
- mapping
- 상속
- 하이버네이트
- 자바
- XML
- Spring
- WebMvc
- jsp
- form
- one-to-many
- Spring Security
- spring boot
- 외부파일
- 스프링
- 로그인
- Angular
- Rest
- Security
- Validation
- Many-To-Many
250x250