Java 既然我的类字段有注释,为什么Field.isAnnotationPresent(fieldDescriptorAnotation.class)在spring引导应用程序中返回false?

Java 既然我的类字段有注释,为什么Field.isAnnotationPresent(fieldDescriptorAnotation.class)在spring引导应用程序中返回false?,java,spring,spring-boot,classloader,Java,Spring,Spring Boot,Classloader,我有一些带有字段级注释的类,这是我制作的自定义注释。我正在尝试获取我的类中具有此注释的字段。我使用以下方法field.isAnnotationPresent(fieldDescriptorAnotation.class)检查字段是否有注释,并在调用spring启动应用程序之前返回true。但当执行此命令时,意味着应用程序启动SpringApplication.run(C4CacheMainApplication.class,args) 现在,如果我尝试在应用程序启动后运行相同的代码,它将返回fa

我有一些带有字段级注释的类,这是我制作的自定义注释。我正在尝试获取我的类中具有此注释的字段。我使用以下方法
field.isAnnotationPresent(fieldDescriptorAnotation.class)
检查字段是否有注释,并在调用spring启动应用程序之前返回true。但当执行此命令时,意味着应用程序启动
SpringApplication.run(C4CacheMainApplication.class,args)

现在,如果我尝试在应用程序启动后运行相同的代码,它将返回false。我检查注释的类不是spring管理的bean,它们只是简单的POJO。此外,在应用程序启动后,
fieldDescriptorAnotation.class
返回的引用与字段中的引用不同

我无法理解为什么在应用程序启动后
isAnnotationPresent()
开始返回false

    public static void main(String[] args) throws ClassNotFoundException {
    
            Class<?> captchaConfigVo = Class.forName("com.web.common.beans.CaptchaConfigVo");
            Field[] fieldList = org.apache.commons.lang3.reflect.FieldUtils.getAllFields(captchaConfigVo);
            for (Field field : fieldList) {
                if (field.isAnnotationPresent(FieldDescriptorAnnotation.class)) {
                    Annotation annotion = field.getAnnotation(FieldDescriptorAnnotation.class);
                    System.out.println(annotion.toString());
                }
            }
    
            SpringApplication.run(C4CacheMainApplication.class, args);

Class<?> captchaConfigVo1 = Class.forName("com.web.common.beans.CaptchaConfigVo");
            Field[] fieldList = org.apache.commons.lang3.reflect.FieldUtils.getAllFields(captchaConfigVo1);
            for (Field field : fieldList) {
                if (field.isAnnotationPresent(FieldDescriptorAnnotation.class)) {
                    Annotation annotion = field.getAnnotation(FieldDescriptorAnnotation.class);
                    System.out.println(annotion.toString());
                }
            }
    }
public class CaptchaConfigVo extends BaseCacheVo {
        private static final long serialVersionUID = 8098160886428994885L;
        @FieldDescriptorAnnotation(
            fieldName = "captcha_config_id"
        )
        private String captchaConfigId;
        @FieldDescriptorAnnotation(
            fieldName = "captcha_config_abrv"
        )
        private String captchaConfigAbrv;
        @FieldDescriptorAnnotation(
            fieldName = "captcha_config_name"
        )
        private String captchaConfigName;
        @FieldDescriptorAnnotation(
            fieldName = "captcha_config_desc"
        )
        private String captchaConfigDesc;
        @FieldDescriptorAnnotation(
            fieldName = "app_id"
        )
        private String appId;
        @FieldDescriptorAnnotation(
            fieldName = "brand_id"
        )
        //getter setters are ommited
    }


@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD})

public @interface FieldDescriptorAnnotation {
    String fieldName();
}
publicstaticvoidmain(字符串[]args)抛出ClassNotFoundException{
类captchaConfigVo=Class.forName(“com.web.common.beans.captchaConfigVo”);
Field[]fieldList=org.apache.commons.lang3.reflect.FieldUtils.getAllFields(captchaConfigVo);
用于(字段:字段列表){
if(field.isAnnotationPresent(fieldDescriptorAnotation.class)){
Annotation annotion=field.getAnnotation(fieldDescriptorAnotation.class);
System.out.println(annotion.toString());
}
}
run(C4CacheMainApplication.class,args);
Class captchaConfigVo1=Class.forName(“com.web.common.beans.CaptchaConfigVo”);
Field[]fieldList=org.apache.commons.lang3.reflect.FieldUtils.getAllFields(captchaConfigVo1);
用于(字段:字段列表){
if(field.isAnnotationPresent(fieldDescriptorAnotation.class)){
Annotation annotion=field.getAnnotation(fieldDescriptorAnotation.class);
System.out.println(annotion.toString());
}
}
}
公共类CaptchaConfigVo扩展了BaseCacheVo{
私有静态最终长serialVersionUID=8098160886428994885L;
@字段描述符表示法(
fieldName=“验证码配置id”
)
私有字符串captchaConfigId;
@字段描述符表示法(
fieldName=“验证码配置”
)
私有字符串captchaConfigAbrv;
@字段描述符表示法(
fieldName=“验证码配置名称”
)
私有字符串captchaConfigName;
@字段描述符表示法(
fieldName=“验证码配置描述”
)
私有字符串captchaConfigDesc;
@字段描述符表示法(
fieldName=“应用程序id”
)
私有字符串appId;
@字段描述符表示法(
fieldName=“品牌标识”
)
//吸气剂设定器是常用的
}
@保留(RetentionPolicy.RUNTIME)
@目标({ElementType.FIELD,ElementType.METHOD})
public@interface字段描述符表示法{
字符串字段名();
}