Annotation Interface 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 with Component, an entry for that component will be added to the index using the org.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 and com.example.PrivilegedService. While Service isn't directly annotated with Indexed, it is meta-annotated with Component.

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 this AdminService 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 the com.example.AdminService stereotype. If there are more @Indexed interfaces and/or superclasses in the hierarchy, the class will map to all their stereotypes.
Since:
5.0
Author:
Stephane Nicoll