Jose Miguel
Jose Miguel

Reputation: 445

custom annotations && aspects error java.lang.IllegalArgumentException: error Type referred to is not an annotation type

I'm trying to make and aspect around a custom annotation. I have this annotation:

@Target({ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public  @interface  BatchControlAnnotation{
    public Class<?> classType();
    public String batchName() default "none";
}

And I have this aspect pointcut:

    @Around("@annotation(BatchControlAnnotation)")
public Object  beforeBatch(ProceedingJoinPoint punto, BatchControlAnnotation batchControlAnnotation) throws Throwable {
    log.debug("HEMOS ENTRADO EN EL ASPECTO, HEMOS CONSEGUIDO LOS VALIRES DE LA ANOTACION CLASSTYPE : {} BATCHNAME {}", batchControlAnnotation.classType().getName(), batchControlAnnotation.batchName());
    log.debug("before");
    Object obj = null;
    try {
       obj = punto.proceed();
    } catch (Throwable e) {
       log.error(e.getMessage(), e);
       throw e;
    }
    log.debug("after");
    return obj;
}

But I'm getting this error and I can't understand why:

org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error Type referred to is not an annotation type: ******* at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:238) at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:710) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) at com.karabati.ApibackApp.main(ApibackApp.java:61) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

Does anyboy any idea about what's happening? Or how to solve it?

Upvotes: 0

Views: 1206

Answers (1)

Jose Miguel
Jose Miguel

Reputation: 445

Ok I already saw where the problem is.

@Around("@annotation(BatchControlAnnotation)")
public Object  beforeBatch(ProceedingJoinPoint punto, BatchControlAnnotation batchControlAnnotation) throws Throwable

The problem is on this line:

@Around("@annotation(***BatchControlAnnotation***)")

The marked text has to refer to variable name on function beforeBatch definition, I was referring the type. So... changing BatchControlAnnotation to batchControlAnnotation, now it works fine.

It's funny to have to use the variable name instead the type, but is that way....

Upvotes: 0

Related Questions