Class CandidateComponentsIndex
java.lang.Object
org.springframework.context.index.CandidateComponentsIndex
Provide access to the candidates that are defined in
META-INF/spring.components
component index files (see CandidateComponentsIndex(List)
) or registered
programmatically (see CandidateComponentsIndex()
).
An arbitrary number of stereotypes can be registered (and queried) on the index: a
typical example is the fully qualified name of an annotation that flags the class for
a certain use case. The following call returns all the @Component
candidate types for the com.example
package (and its sub-packages):
Set<String> candidates = index.getCandidateTypes( "com.example", "org.springframework.stereotype.Component");
The type
is usually the fully qualified name of a class, though this is
not a rule. Similarly, the stereotype
is usually the fully qualified name of
an annotation type, but it can be any marker really.
- Since:
- 5.0
- Author:
- Stephane Nicoll, Juergen Hoeller
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new index instance for programmatic population. -
Method Summary
Modifier and TypeMethodDescriptiongetCandidateTypes
(String basePackage, String stereotype) Return the candidate types that are associated with the specified stereotype.Return the registered base packages (or base package patterns).Return the registered stereotype packages (or base package patterns).boolean
hasScannedPackage
(String packageName) Determine whether this index contains an entry for the given base package (or base package pattern).void
registerCandidateType
(String type, String... stereotypes) Programmatically register one or more stereotypes for the given candidate type.void
registerScan
(String... basePackages) Programmatically register the given base packages (or base package patterns) as scanned.
-
Constructor Details
-
CandidateComponentsIndex
public CandidateComponentsIndex()Create a new index instance for programmatic population.- Since:
- 7.0
- See Also:
-
-
Method Details
-
registerScan
Programmatically register the given base packages (or base package patterns) as scanned.- Since:
- 7.0
- See Also:
-
getRegisteredScans
-
hasScannedPackage
Determine whether this index contains an entry for the given base package (or base package pattern).- Since:
- 7.0
-
registerCandidateType
Programmatically register one or more stereotypes for the given candidate type.Note that the containing packages for candidates are not automatically considered scanned packages. Make sure to call
registerScan(String...)
with the scan-specific base package accordingly.- Since:
- 7.0
- See Also:
-
getRegisteredStereotypes
-
getCandidateTypes
Return the candidate types that are associated with the specified stereotype.- Parameters:
basePackage
- the package to check for candidatesstereotype
- the stereotype to use- Returns:
- the candidate types associated with the specified
stereotype
or an empty set if none has been found for the specifiedbasePackage
-