Interface PackageScanClassResolver
- All Superinterfaces:
AutoCloseable, Service, StaticService
Classpath scanning strategy for discovering classes by annotation, supertype, or custom predicate across one or more
packages, used by Camel at startup to auto-detect components, type converters, and other pluggable types.
The resolver scans all registered
ClassLoader instances for .class files under the specified package
names (including sub-packages). Results are internally cached; call clearCache() to invalidate the cache
when the classpath changes at runtime (for example, in OSGi or hot-deployment environments).
Global filters added via addFilter(PackageScanFilter) are applied to every subsequent scan operation, which
is useful for excluding test or internal classes from production discovery.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddClassLoader(ClassLoader classLoader) Adds the class loader to the existing loadersvoidaddFilter(PackageScanFilter filter) Add a filter that will be applied to all scan operationsvoidClears and frees the internal cache.findAnnotated(Class<? extends Annotation> annotation, String... packageNames) Attempts to discover classes that are annotated with to the annotation.findAnnotated(Set<Class<? extends Annotation>> annotations, String... packageNames) Attempts to discover classes that are annotated with to the annotation.findByFilter(PackageScanFilter filter, String... packageNames) Attempts to discover classes filter by the provided filterfindImplementations(Class<?> parent, String... packageNames) Attempts to discover classes that are assignable to the type provided (exclude abstract classes).Gets the ClassLoader instances that should be used when scanning for classes.voidremoveFilter(PackageScanFilter filter) Removes the filtervoidsetAcceptableSchemes(String schemes) To specify a set of accepted schemas to use for loading resources as URL connections (besides http and https schemas)
-
Method Details
-
getClassLoaders
Set<ClassLoader> getClassLoaders()Gets the ClassLoader instances that should be used when scanning for classes. This implementation will return a new unmodifiable set containing the classloaders. Use theaddClassLoader(ClassLoader)method if you want to add new classloaders to the class loaders list.- Returns:
- the class loaders to use
-
addClassLoader
Adds the class loader to the existing loaders- Parameters:
classLoader- the loader to add
-
findAnnotated
Attempts to discover classes that are annotated with to the annotation.- Parameters:
annotation- the annotation that should be present on matching classespackageNames- one or more package names to scan (including subpackages) for classes- Returns:
- the classes found, returns an empty set if none found
-
findAnnotated
Attempts to discover classes that are annotated with to the annotation.- Parameters:
annotations- the annotations that should be present (any of them) on matching classespackageNames- one or more package names to scan (including subpackages) for classes- Returns:
- the classes found, returns an empty set if none found
-
findImplementations
Attempts to discover classes that are assignable to the type provided (exclude abstract classes). In the case that an interface is provided this method will collect implementations. In the case of a non-interface class, subclasses will be collected.- Parameters:
parent- the class of interface to find subclasses or implementations ofpackageNames- one or more package names to scan (including subpackages) for classes- Returns:
- the classes found, returns an empty set if none found
-
findByFilter
Attempts to discover classes filter by the provided filter- Parameters:
filter- filter to filter desired classes.packageNames- one or more package names to scan (including subpackages) for classes- Returns:
- the classes found, returns an empty set if none found
-
addFilter
Add a filter that will be applied to all scan operations- Parameters:
filter- filter to filter desired classes in all scan operations
-
removeFilter
Removes the filter- Parameters:
filter- filter to filter desired classes in all scan operations
-
setAcceptableSchemes
To specify a set of accepted schemas to use for loading resources as URL connections (besides http and https schemas) -
clearCache
void clearCache()Clears and frees the internal cache.
-