error Type referred to is not an annotation type:

Acdc RocknRoll picture Acdc RocknRoll · Dec 20, 2011 · Viewed 22.1k times · Source

I got the following Aspect

@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();
}

and this Annotation:

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

Role[] value();

}

I get the error:error Type referred to is not an annotation type: denyForTeam

Why is DenyForTeam no Annotation? It is marked with @interface

Answer

yuqizhang picture yuqizhang · Feb 21, 2019

I solved my issue by specifying the package explicitly

change the following

@Around("@annotation(SessionCheck)")
public Object checkSessionState(ProceedingJoinPoint joinPoint) throws Throwable {
    // code here 
}

to

@Around("@annotation(my.aop.annotation.SessionCheck)")
public Object checkSessionState(ProceedingJoinPoint joinPoint) throws Throwable {
    // code here
}

or put them in the same package