error Type referred to is not an annotation type:
Asked Answered
P

3

30

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

Persinger answered 20/12, 2011 at 10:57 Comment(0)
S
26

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
{
Skipton answered 20/12, 2011 at 11:3 Comment(2)
one more thing the annotation name is case sensitive @annotation(DenyForTeam) don't work. It should be @annotation(denyForTeam)Nicobarese
your answer was very simple and helpful.Regardless
C
58

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

Coinsure answered 21/2, 2019 at 11:19 Comment(0)
S
26

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
{
Skipton answered 20/12, 2011 at 11:3 Comment(2)
one more thing the annotation name is case sensitive @annotation(DenyForTeam) don't work. It should be @annotation(denyForTeam)Nicobarese
your answer was very simple and helpful.Regardless
P
3

thanks a lot, I solved my issue by specifying the package correct

change the following

    @Around("@annotation(org.asx.org.wz.xx.log.annotaion.OperationLog)")
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
     // your code
}

to

    @Around("@annotation(org.asx.xx.log.annotaion.OperationLog)")
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
     // your code
}

my package was wrong, correct it and then problem solved. try to check your package name serious again

Pokey answered 25/3, 2023 at 15:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.