error引用的类型不是注释类型:

问题描述 投票:9回答:2

我有以下看点

@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

spring aop spring-aop
2个回答
15
投票

需要有一个名为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
{

6
投票

我通过明确指定包解决了我的问题

改变以下

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

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

或者将它们放在同一个包装中

© www.soinside.com 2019 - 2024. All rights reserved.