within(Type)은 Type 안에 클래스 타입을 넣어줍니다. 그러면 그 클래스에 있는 메소드가 실행되는 시점들(Join point)을 포인트컷으로 묶습니다.

이번 예제 소스는 아래 파일에 있습니다.
bl193.zip

@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))[footnote]Pointcut들에 ||, &&, ! 연산을 할 수 있으며 의미는 알고 계신 의미와 동일합니다.[/footnote] 은 Keesun 클래스와 Youngkun클래스의 메소드를 호출하는 모든 Join point를 나타내게 됩니다.

두 클래스 모두 Human이라는 클래스를 구현하였기 때문에 within(Human)으로 하고 싶지만 Human은 인터페이스 이기 때문에 객체를 만들수 없으며 따라서 Human 객체의 메소드를 호출할 수도 없고 그럴 일도 없기 때문에 적용이 되지 않습니다. 이럴 때는 this를 사용합니다. 다음과 같이 수정하시면 위의 코드와 동일 한 결과를 얻을 수 있습니다.

@Aspect

public class MannerAOP {

 

       @Pointcut("this(Human)")

       public void sayGoodBye(){}

 

       @AfterReturning("sayGoodBye()")

       public void say(){

             System.out.println("안녕히 가세요.");

       }

}