【问题标题】:error Type referred to is not an annotation type:引用的错误类型不是注释类型:
【发布时间】:2011-12-20 10:57:07
【问题描述】:

我得到了以下方面

@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


    【解决方案1】:

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

    改变以下内容

    @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
    }
    

    或者放在同一个包里

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 注释名称区分大小写的另一件事 @annotation(DenyForTeam) 不起作用。应该是@annotation(denyForTeam)
      猜你喜欢
      • 2018-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      相关资源
      最近更新 更多