自定义注释&&方面错误java.lang.IllegalArgumentException:错误引用的类型不是注释类型

时间:2019-03-20 11:38:38

标签: java spring-boot aop java-annotations

我正在尝试围绕自定义注释进行制作。 我有这个注释:

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

我有这个方面切入点:

    @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;
}

但是我遇到此错误,我不明白为什么:

  

org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration':   Bean初始化失败;嵌套异常为   java.lang.IllegalArgumentException:错误引用的类型不是   注释类型:*******           在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)处           在org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:317)           在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)           在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)           在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204)           在org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:238)处           在org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:710)           在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535)           在org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)           在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)           在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)           在org.springframework.boot.SpringApplication.run(SpringApplication.java:327)           在com.karabati.ApibackApp.main(ApibackApp.java:61)           在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处           在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)           在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)           在java.lang.reflect.Method.invoke(Method.java:498)           在org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

任何男孩都对发生的事情有任何想法吗?或如何解决?

1 个答案:

答案 0 :(得分:0)

好的,我已经知道问题出在哪里了。

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

问题在此行上:

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

标记的文本必须引用函数beforeBatch定义上的变量名,我正在引用类型。所以...将BatchControlAnnotation更改为batchControlAnnotation,现在可以正常使用了。

必须使用变量名代替类型,这很有趣,但是就是那样。...