注释类型 Indexed
@Target(TYPE) @Retention(RUNTIME) @Documented public @interface Indexed
Indicate that the annotated element represents a stereotype for the index.The
CandidateComponentsIndex
is an alternative to classpath scanning that uses a metadata file generated at compilation time. The index allows retrieving the candidate components (i.e. fully qualified name) based on a stereotype. This annotation instructs the generator to index the element on which the annotated element is present or if it implements or extends from the annotated element. The stereotype is the fully qualified name of the annotated element.Consider the default
Component
annotation that is meta-annotated with this annotation. If a component is annotated withComponent
, an entry for that component will be added to the index using theorg.springframework.stereotype.Component
stereotype.This annotation is also honored on meta-annotations. Consider this custom annotation:
package com.example; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Indexed @Service public @interface PrivilegedService { ... }
If the above annotation is present on a type, it will be indexed with two stereotypes:org.springframework.stereotype.Component
andcom.example.PrivilegedService
. WhileService
isn't directly annotated withIndexed
, it is meta-annotated withComponent
.It is also possible to index all implementations of a certain interface or all the subclasses of a given class by adding
@Indexed
on it. Consider this base interface:package com.example; @Indexed public interface AdminService { ... }
Now, consider an implementation of thisAdminService
somewhere:package com.example.foo; import com.example.AdminService; public class ConfigurationAdminService implements AdminService { ... }
Because this class implements an interface that is indexed, it will be automatically included with thecom.example.AdminService
stereotype. If there are more@Indexed
interfaces and/or superclasses in the hierarchy, the class will map to all their stereotypes.- 从以下版本开始:
- 5.0
- 作者:
- Stephane Nicoll