2012-09-28 4 views
0

주석 처리 된 메소드에 대한 pointcut으로 Aspect를 생성했습니다. 내가 JoinPoint으로 얻는 것은 인터페이스 구현이 아니라 메소드 구현으로부터의 메소드 선언입니다. 그래서 주석이 달린 메소드 매개 변수를 가져 오려면 구현에 인터페이스가 아닌 주석을 추가해야합니다.메소드 구현의 포인트 컷

@AfterReturning(value = "@annotation(pl.styall.scylla.security.authorization.acl.AclSecure) && @annotation(aclSecure)", argNames = "jp,aclSecure,retVal", returning = "retVal") 
public void addObjectAndEntry(JoinPoint jp, AclSecure aclSecure, 
     Object retVal) { 
    System.out.println(jp.toLongString()); 
    MethodSignature signature = (MethodSignature) jp.getSignature(); 
    Method method = signature.getMethod(); 
    Annotation[][] methodAnnotations = method.getParameterAnnotations(); 

methodAnnotations은 메서드 구현에 추가되는 주석이 없습니다. 올바른 pointcut은 무엇입니까?

답변

2
final String methodName = pjp.getSignature().getName(); 
final MethodSignature methodSignature = (MethodSignature)pjp.getSignature(); 
Method method = methodSignature.getMethod(); 
if (method.getDeclaringClass().isInterface()) { 
    method = pjp.getTarget().getClass().getDeclaredMethod(methodName, method.getParameterTypes());  
} 

출처 : Spring AOP: how to get the annotations of the adviced method

관련 문제