11. within 포인트컷 & this 포인트컷 사용하기
이번 예제 소스는 아래 파일에 있습니다.
@Aspect
public class MannerAOP {
@Pointcut("within(Keesun) || within(Youngkun)")
public void sayGoodBye(){}
@AfterReturning("sayGoodBye()")
public void say(){
System.out.println("안녕히 가세요.");
}
}
여기서 @Pointcut(within(Keesun) || within(Youngkun)) 은 Keesun 클래스와 Youngkun클래스의 메소드를 호출하는 모든 Join point를 나타내게 됩니다. 1
두 클래스 모두 Human이라는 클래스를 구현하였기 때문에 within(Human)으로 하고 싶지만 Human은 인터페이스 이기 때문에 객체를 만들수 없으며 따라서 Human 객체의 메소드를 호출할 수도 없고 그럴 일도 없기 때문에 적용이 되지 않습니다. 이럴 때는 this를 사용합니다. 다음과 같이 수정하시면 위의 코드와 동일 한 결과를 얻을 수 있습니다.
@Aspect
public class MannerAOP {
@Pointcut("this(Human)")
public void sayGoodBye(){}
@AfterReturning("sayGoodBye()")
public void say(){
System.out.println("안녕히 가세요.");
}
}
- Pointcut들에 ||, &&, ! 연산을 할 수 있으며 의미는 알고 계신 의미와 동일합니다. [본문으로]
'AOP' 카테고리의 다른 글
Spring AOP(old) 특징 (0) | 2007.03.28 |
---|---|
3월달 마소 AOP 기사 정리 (0) | 2007.03.27 |
Eclipse에서 AspectJ 개발 동영상입니다. (0) | 2007.02.15 |
AOP: Radical Research in Modularity (4) | 2007.02.04 |
12. Advice parameters 1 (2) | 2007.01.17 |
11. within 포인트컷 & this 포인트컷 사용하기 (0) | 2007.01.16 |
10. execution 포인트컷 사용하기 (0) | 2007.01.16 |
9. @AspectJ의 Pointcut 살펴보기 2 (0) | 2007.01.16 |
8. @AspectJ의 Pointcut 살펴보기 1 (0) | 2007.01.16 |
7. @AspectJ 사용하는 초간단 AOP 예제 2 (6) | 2007.01.13 |
6. Join Points and Pointcuts (0) | 2007.01.12 |