public class DefaultResourceLoader extends Object implements ResourceLoader
ResourceLoader interface. Used by
ResourceEditor, and serves as base class for
org.springframework.context.support.AbstractApplicationContext. Can
also be used standalone.
Will return a UrlResource if the location value is a URL, and a
ClassPathResource if it is a non-URL path or a "classpath:"
pseudo-URL.
FileSystemResourceLoader,
org.springframework.context.support.ClassPathXmlApplicationContext| Modifier and Type | Class and Description |
|---|---|
protected static class |
DefaultResourceLoader.ClassPathContextResource
ClassPathResource that explicitly expresses a context-relative path
through implementing the ContextResource interface.
|
CLASSPATH_URL_PREFIX| Constructor and Description |
|---|
DefaultResourceLoader()
Create a new DefaultResourceLoader.
|
DefaultResourceLoader(ClassLoader classLoader)
Create a new DefaultResourceLoader.
|
| Modifier and Type | Method and Description |
|---|---|
ClassLoader |
getClassLoader()
Return the ClassLoader to load class path resources with.
|
Resource |
getResource(String location)
Return a Resource handle for the specified resource.
|
protected Resource |
getResourceByPath(String path)
Return a Resource handle for the resource at the given path.
|
void |
setClassLoader(ClassLoader classLoader)
Specify the ClassLoader to load class path resources with, or
null for using the thread context class loader at the time of
actual resource access. |
public DefaultResourceLoader()
ClassLoader access will happen using the thread context class loader at the time of this ResourceLoader's initialization.
Thread.getContextClassLoader()public DefaultResourceLoader(ClassLoader classLoader)
classLoader - the ClassLoader to load class path resources with, or
null for using the thread context class loader at the
time of actual resource accesspublic void setClassLoader(ClassLoader classLoader)
null for using the thread context class loader at the time of
actual resource access.
The default is that ClassLoader access will happen using the thread context class loader at the time of this ResourceLoader's initialization.
public ClassLoader getClassLoader()
Will get passed to ClassPathResource's constructor for all ClassPathResource objects created by this resource loader.
getClassLoader in interface ResourceLoadernull if even the system ClassLoader
isn't accessible)ClassPathResourcepublic Resource getResource(String location)
ResourceLoaderInputStreamSource.getInputStream() calls.
Note that a Resource handle does not imply an existing resource; you need
to invoke Resource.exists() to check for existence.
getResource in interface ResourceLoaderlocation - the resource locationResourceLoader.CLASSPATH_URL_PREFIX,
org.hotswap.agent.util.spring.io.resource.springframework.core.io.Resource#exists,
org.hotswap.agent.util.spring.io.resource.springframework.core.io.Resource#getInputStreamprotected Resource getResourceByPath(String 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.
path - the path to the resourceClassPathResource,
org.springframework.context.support.FileSystemXmlApplicationContext#getResourceByPath,
org.springframework.web.context.support.XmlWebApplicationContext#getResourceByPathCopyright © 2018. All rights reserved.