2011-05-05 2 views
0

내가 방법을 다음에서 문자열을 인쇄 할 수있는 포인트 컷과 조언을 쓰기 위해 노력하고 내부 변수를 인쇄 -AspectJ의 포인트 컷은 로컬 방법 코드를 성찰하고 현지 법

public CustomerDto getCustomer(Integer customerCode){   
      CustomerDto customerDto = new CustomerDto();   
      String emailID =getEmailAddress(); 
      customerDto.setEmailAddress(emailID);    
      customerDto.setEmployer(getEmployer()); 
      customerDto.setSpouseName(getSpouse()); 
      return customerDto;  
} 

나는 알아낼 수없는 오전을 방법은 pointcut에서 StringEditID를보고 조언에있는 값을 인쇄하는 방법입니다.

+0

나는 당신이 뭘 하려는지 모르겠습니다. getCustomer가 실행될 때마다 조언을 실행하려고합니까? –

답변

2

은 아마 당신은 다음과 같은 뭔가가 필요 : TargetClassgetCustomer()getEmailAddress() 방법을 포함하는 클래스입니다

public privileged aspect LocalMethodCallAspect { 
    private pointcut localMethodExecution() : withincode(public CustomerDto TargetClass.getCustomer(Integer)) && 
     call(private String TargetClass.getEmailAddress()); 

    after() returning(String email) : localMethodExecution() 
    { 
     System.out.println(email); 
    } 
} 

.

또는 같은 사용 @AspectJ :

@Aspect 
public class LocalMethodCallAnnotationDrivenAspect { 
    @Pointcut("withincode(public CustomerDto TargetClass.getCustomer(Integer)) && " + 
      "call(private String TargetClass.getEmailAddress())") 
    private void localMethodExecution() { 

    } 

    @AfterReturning(pointcut="localMethodExecution()",returning="email") 
    public void printingEmail(String email) { 
     System.out.println(email); 
    } 
} 
+0

이 질문은 오래된 질문이지만, @AspectJ 부분을 사용할 수는 없습니다. ''withincode'를 사용할 때' 'pointcut expression'localMethodExecution() '에 지원되지 않는 pointcut primitive'withincode '가 포함되어 있습니다. '@ withincode'를 시도하면'Pointcut is well-formed : expecting ')'at 문자 위치 19 @withincode (public int com .....' Spring 설명서에서 _Spring_은'withincode'와'@ withincode '를 지원하지 않는다고하지만 AspectJ 주석을 사용하고 있습니다. 그것이 작동하지 않는 이유는 무엇입니까? – Roger

+0

@Roger 새로운 질문이 있습니다. –