Java基础之《注解2》

1、除了@Target、@Retention、@Documented、@Inherited外,JDK1.8新增了一个元注解@Repeatable
@Repeatable注解也是在java.lang.annotation包下:

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Repeatable {
    /**
     * Indicates the <em>containing annotation type</em> for the
     * repeatable annotation type.
     * @return the containing annotation type
     */
    Class<? extends Annotation> value();
}

2、作用
表示被修饰的注解,可以同时使用多次,比如@ComponentScan注解,我们可以定义多个扫描路径

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Repeatable(ComponentScans.class)
public @interface ComponentScan {
...
}

3、多个ComponentScan的路径配置,包含在ComponentScans.class内,集合成一个数组

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
public @interface ComponentScans {

	ComponentScan[] value();

}