Class DefaultClassPathResourceLoader
java.lang.Object
io.micronaut.core.io.scan.DefaultClassPathResourceLoader
- All Implemented Interfaces:
ResourceLoader, ClassPathResourceLoader
@NullMarked
public class DefaultClassPathResourceLoader
extends Object
implements ClassPathResourceLoader
Loads resources from the classpath.
- Since:
- 1.0
- Author:
- James Kleeh, graemerocher
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultClassPathResourceLoader(ClassLoader classLoader) Default constructor.DefaultClassPathResourceLoader(ClassLoader classLoader, @Nullable String basePath) Use when resources should have a standard base path.DefaultClassPathResourceLoader(ClassLoader classLoader, @Nullable String basePath, boolean checkBase) Use when resources should have a standard base path.DefaultClassPathResourceLoader(ClassLoader classLoader, @Nullable String basePath, boolean checkBase, boolean logEnabled) Use when resources should have a standard base path. -
Method Summary
Modifier and TypeMethodDescriptionConstructs a new resource loader designed to load resources from the given path.Need this method to ability disable Slf4J initizalization.Returns the underlying classloader used by thisClassPathResourceLoader.getResource(String path) Obtains a resource URL.getResourceAsStream(String path) Obtains a resource as a stream.getResources(String path) Obtains a stream of resource URLs.voidreportResourceDuplicates(String resourceName, URL chosen, List<URL> duplicates) Hook to handle duplicate resources forResourceLoadStrategyType.FIRST_MATCH.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ClassPathResourceLoader
handleResourceDuplicates, supportsPrefix
-
Constructor Details
-
DefaultClassPathResourceLoader
Default constructor.- Parameters:
classLoader- The class loader for loading resources
-
DefaultClassPathResourceLoader
Use when resources should have a standard base path.- Parameters:
classLoader- The class loader for loading resourcesbasePath- The path to look for resources under
-
DefaultClassPathResourceLoader
public DefaultClassPathResourceLoader(ClassLoader classLoader, @Nullable String basePath, boolean checkBase) Use when resources should have a standard base path.- Parameters:
classLoader- The class loader for loading resourcesbasePath- The path to look for resources undercheckBase- If set totruean extended check for the base path is performed otherwise paths with relative URLs like../are prohibited.
-
DefaultClassPathResourceLoader
public DefaultClassPathResourceLoader(ClassLoader classLoader, @Nullable String basePath, boolean checkBase, boolean logEnabled) Use when resources should have a standard base path.- Parameters:
classLoader- The class loader for loading resourcesbasePath- The path to look for resources undercheckBase- If set totruean extended check for the base path is performed otherwise paths with relative URLs like../are prohibited.logEnabled- flag to enable or disable logger
-
-
Method Details
-
reportResourceDuplicates
Description copied from interface:ResourceLoaderHook to handle duplicate resources forResourceLoadStrategyType.FIRST_MATCH. Default implementation is a no-op.- Specified by:
reportResourceDuplicatesin interfaceResourceLoader- Parameters:
resourceName- The resource namechosen- The chosen resource URLduplicates- The duplicate resource URLs
-
getResourceAsStream
Obtains a resource as a stream.- Specified by:
getResourceAsStreamin interfaceResourceLoader- Parameters:
path- The path- Returns:
- An optional resource
-
getResource
Obtains a resource URL.- Specified by:
getResourcein interfaceResourceLoader- Parameters:
path- The path- Returns:
- An optional resource
-
getResources
Obtains a stream of resource URLs.- Specified by:
getResourcesin interfaceResourceLoader- Parameters:
path- The path- Returns:
- A resource stream
-
getClassLoader
Description copied from interface:ClassPathResourceLoaderReturns the underlying classloader used by thisClassPathResourceLoader.- Specified by:
getClassLoaderin interfaceClassPathResourceLoader- Returns:
- The class loader used to retrieve resources
-
forBase
Description copied from interface:ResourceLoaderConstructs a new resource loader designed to load resources from the given path. Requested resources will be loaded within the context of the given path.- Specified by:
forBasein interfaceResourceLoader- Parameters:
basePath- The path to load resources- Returns:
- The resource loader
-
forBase
Need this method to ability disable Slf4J initizalization.- Parameters:
basePath- The path to load resourceslogEnabled- flag to enable or disable logger- Returns:
- The resource loader
-