error Type referred to is not an annotation type:

不想你离开。 提交于 2019-12-20 18:32:39

问题


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


回答1:


There needs to be a method argument of the name denyForTeam whose type should be DenyForTeam annotation. @annotation - bind the annotation to a method argument with the same name.

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

If you don't want the annotation passed as an argument then include the @DenyForTeam (full qualified) in the pointcut expression.

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



回答2:


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



来源:https://stackoverflow.com/questions/8574348/error-type-referred-to-is-not-an-annotation-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!