@Repeatable(重复注解)注解有什么用?
什么是重复注解
(java.lang.annotation.Repeatable)定义的源码。
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Repeatable {
class<? extends Annotation> value( );
}
重复注解,即一个注解可以在一个类、方法或者字段上同时使用多次,如Spring中可以使用多个扫描组件来扫描多个包的注解。
@Repeatable(重复注解)在哪里有用到?
- Spring中可以使用多个扫描组件来扫描多个包的注解。
- @ComponentScan @ComponentScans 都被@Repeatable修饰