Class DefaultResourceLoader
- All Implemented Interfaces:
ResourceLoader
Used by {link ResourceEditor}, and serves as base class for {link org.springframework.context.support.AbstractApplicationContext}. Can also be used standalone.
Will return a {link UrlResource} if the location value is a URL, and a {link ClassPathResource} if it is a non-URL path or a "classpath:" pseudo-URL.
- Since:
- 10.03.2004
- Author:
- Juergen Hoeller see FileSystemResourceLoader see org.springframework.context.support.ClassPathXmlApplicationContext
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
ClassPathResource that explicitly expresses a context-relative path through implementing the ContextResource interface. -
Field Summary
Fields inherited from interface nl.basjes.parse.useragent.utils.springframework.core.io.ResourceLoader
CLASSPATH_URL_PREFIX
-
Constructor Summary
ConstructorDescriptionCreate a new DefaultResourceLoader.DefaultResourceLoader
(ClassLoader classLoader) Create a new DefaultResourceLoader. -
Method Summary
Modifier and TypeMethodDescriptionReturn the ClassLoader to load class path resources with.Return the collection of currently registered protocol resolvers, allowing for introspection as well as modification.getResource
(String location) Return aResource
handle for the specified resource location.protected Resource
getResourceByPath
(String path) Return a Resource handle for the resource at the given path.
-
Constructor Details
-
DefaultResourceLoader
public DefaultResourceLoader()Create a new DefaultResourceLoader.ClassLoader access will happen using the thread context class loader at the time of actual resource access (since 5.3). For more control, pass a specific ClassLoader to {link #DefaultResourceLoader(ClassLoader)}. see java.lang.Thread#getContextClassLoader()
-
DefaultResourceLoader
Create a new DefaultResourceLoader.- Parameters:
classLoader
- the ClassLoader to load class path resources with, ornull
for using the thread context class loader at the time of actual resource access
-
-
Method Details
-
getClassLoader
Return the ClassLoader to load class path resources with.Will get passed to ClassPathResource's constructor for all ClassPathResource objects created by this resource loader. see ClassPathResource
- Specified by:
getClassLoader
in interfaceResourceLoader
- Returns:
- the
ClassLoader
(onlynull
if even the systemClassLoader
isn't accessible) see org.springframework.util.ClassUtils#getDefaultClassLoader() see org.springframework.util.ClassUtils#forName(String, ClassLoader)
-
getProtocolResolvers
Return the collection of currently registered protocol resolvers, allowing for introspection as well as modification. see #addProtocolResolver(ProtocolResolver)- Since:
- 4.3
-
getResource
Description copied from interface:ResourceLoader
Return aResource
handle for the specified resource location.The handle should always be a reusable resource descriptor, allowing for multiple {link Resource#getInputStream()} calls.
- Must support fully qualified URLs, e.g. "file:C:/test.dat".
- Must support classpath pseudo-URLs, e.g. "classpath:test.dat".
- Should support relative file paths, e.g. "WEB-INF/test.dat". (This will be implementation-specific, typically provided by an ApplicationContext implementation.)
Note that a
Resource
handle does not imply an existing resource; you need to invoke {link Resource#exists} to check for existence.- Specified by:
getResource
in interfaceResourceLoader
- Parameters:
location
- the resource location- Returns:
- a corresponding
Resource
handle (nevernull
) see #CLASSPATH_URL_PREFIX see Resource#exists() see Resource#getInputStream()
-
getResourceByPath
Return a Resource handle for the resource at the given path.The default implementation supports class path locations. This should be appropriate for standalone implementations but can be overridden, e.g. for implementations targeted at a Servlet container.
- Parameters:
path
- the path to the resource- Returns:
- the corresponding Resource handle see ClassPathResource see org.springframework.context.support.FileSystemXmlApplicationContext#getResourceByPath see org.springframework.web.context.support.XmlWebApplicationContext#getResourceByPath
-