2011-12-20 33 views
4

我有以下看點錯誤類型所指的,不是註釋類型:

@Around("execution(public * (@DisabledForBlockedAccounts *).*(..))" + " && @annotation(denyForTeam)") 
public Object translateExceptionsDenySelectedAccount(ProceedingJoinPoint pjp, Deny deny) throws Throwable 
{ 
    Account account = (Account) pjp.getArgs()[0]; 
    Account selectedAccount = (Account) pjp.getArgs()[1]; 

    if (ArrayUtils.contains(deny.value(), account.getRole())) 
    { 

     if (account.getType().equals(Type.CHEF) && !selectedAccount.getType().equals(Type.CHEF)) 
     { 
      throw new IllegalAccessException(""); 
     } 
    } 
    return pjp.proceed(); 
} 

這譯註:

@Target({TYPE, METHOD, FIELD}) 
@Retention(RUNTIME) 
public @interface DenyForTeam 
{ 

Role[] value(); 

} 

我得到的錯誤:指錯誤類型未註釋類型:denyForTeam

爲什麼DenyForTeam沒有註釋?它標有@interface

回答

12

需要有名稱爲denyForTeam的方法參數,其類型應該是DenyForTeam註釋。 @annotation - 將註釋綁定到具有相同名稱的方法參數。

@Around("execution(public * (@DisabledForBlockedAccounts *).*(..))" + " && @annotation(denyForTeam)") 
public Object translateExceptionsDenySelectedAccount(ProceedingJoinPoint pjp, Deny deny, DenyForTeam denyForTeam) throws Throwable 
{ 

如果你不想作爲參數傳遞的註解則包括切入點表達式的@DenyForTeam(完全限定)。

@Around("execution(@DenyForTeam public * (@DisabledForBlockedAccounts *).*(..))") 
public Object translateExceptionsDenySelectedAccount(ProceedingJoinPoint pjp, Deny deny) throws Throwable 
{ 
+0

非常感謝! – 2011-12-20 11:11:21

+0

您能否請您將答案標記爲已接受。 – gkamal 2011-12-20 11:17:44

+0

註解名稱區分大小寫@annotation(DenyForTeam)不起作用。它應該是@annotation(denyForTeam) – Chandru 2016-12-21 16:39:41