0

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?

1 Answer 1

1

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 the variable name of the second parameter definition on the beforeBatch method, I was referring the type.

So... changing

  • From @Around("@annotation(BatchControlAnnotation)")
  • To @Around("@annotation(batchControlAnnotation)")

now it works fine.

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.