我有以下方面
@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
答案 0 :(得分: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
{
答案 1 :(得分: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
}
或将它们放在同一包装中