Acd*_*oll 12 aop spring spring-aop
我有以下看点
@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();
}
Run Code Online (Sandbox Code Playgroud)
和这个注释:
@Target({TYPE, METHOD, FIELD})
@Retention(RUNTIME)
public @interface DenyForTeam
{
Role[] value();
}
Run Code Online (Sandbox Code Playgroud)
我得到错误:错误引用的类型不是注释类型:denyForTeam
为什么DenyForTeam没有注释?它标有@interface
gka*_*mal 15
需要有一个名为denyForTeam的方法参数,其类型应为DenyForTeam注释.@annotation - 将注释绑定到具有相同名称的方法参数.
@Around("execution(public * (@DisabledForBlockedAccounts *).*(..))" + " && @annotation(denyForTeam)")
public Object translateExceptionsDenySelectedAccount(ProceedingJoinPoint pjp, Deny deny, DenyForTeam denyForTeam) throws Throwable
{
Run Code Online (Sandbox Code Playgroud)
如果您不希望将注释作为参数传递,则在切入点表达式中包含@DenyForTeam(完全限定).
@Around("execution(@DenyForTeam public * (@DisabledForBlockedAccounts *).*(..))")
public Object translateExceptionsDenySelectedAccount(ProceedingJoinPoint pjp, Deny deny) throws Throwable
{
Run Code Online (Sandbox Code Playgroud)
我通过明确指定软件包解决了我的问题
改变以下
@Around("@annotation(SessionCheck)")
public Object checkSessionState(ProceedingJoinPoint joinPoint) throws Throwable {
// code here
}
Run Code Online (Sandbox Code Playgroud)
至
@Around("@annotation(my.aop.annotation.SessionCheck)")
public Object checkSessionState(ProceedingJoinPoint joinPoint) throws Throwable {
// code here
}
Run Code Online (Sandbox Code Playgroud)
或将它们放在同一包装中
| 归档时间: |
|
| 查看次数: |
17905 次 |
| 最近记录: |