想写一个注解,组合 @Resource  @Lazy 为一个新注解,结果证实无效, 这个变量不给注入了。
  搜了半天: @Resource注解是CommonAnnotationBeanPostProcessor.java处理的。
  判断字段上是否存在@Resource注解 field.isAnnotationPresent(Resource.class)
  field对象继承AccessibleObject.java,内有     /**      * @since 1.5      */     public Annotation[] getAnnotations() {         return getDeclaredAnnotations();     }
  顶层接口中,注释说,getAnnotations应该返回所有注解,包括继承的。 getDeclaredAnnotations返回直接写的注解。 但是,这里getAnnotations调的getDeclaredAnnotations()方法,所以一码事。
  所以,应该@Resouce注解只能直接写上,不能放到新注解里了。 ---------- @Autowired注解是AutowiredAnnotationBeanPostProcessor.java处理的,应该类似。 ------------------
  public class AAA {
      @LazyResource     @Autowired     String aaa="1";
      public static void main(String[] args) throws NoSuchFieldException {         Field field = AAA.class.getDeclaredField("aaa");         Annotation[] an = field.getAnnotations();         for(Annotation a:an){             System.out.println(a);         }         System.out.println(field.isAnnotationPresent(Resource.class));         System.out.println(field.isAnnotationPresent(LazyResource.class));     } }
  输出: @cn.com.tcsl.framework.spring.annotation.LazyResource(name=) @org.springframework.beans.factory.annotation.Autowired(required=true) false true -------------------------------- 发现个文章:https://hankmo.com/posts/tech/annotated-element/ 可以读读。 
 |