public class

DefaultResourceLoader

extends Object
implements ResourceLoader
java.lang.Object
   ↳ org.springframework.core.io.DefaultResourceLoader
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Default implementation of the ResourceLoader interface. Used by ResourceEditor, and serves as base class for 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.

Summary

[Expand]
Inherited Constants
From interface org.springframework.core.io.ResourceLoader
Public Constructors
DefaultResourceLoader()
Create a new DefaultResourceLoader.
DefaultResourceLoader(ClassLoader classLoader)
Create a new DefaultResourceLoader.
Public Methods
ClassLoader getClassLoader()
Return the ClassLoader to load class path resources with.
Resource getResource(String location)
Return a Resource handle for the specified resource.
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.
Protected Methods
Resource getResourceByPath(String path)
Return a Resource handle for the resource at the given path.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.core.io.ResourceLoader

Public Constructors

public DefaultResourceLoader ()

Also: SpringCore

Create a new DefaultResourceLoader.

ClassLoader access will happen using the thread context class loader at the time of this ResourceLoader's initialization.

public DefaultResourceLoader (ClassLoader classLoader)

Also: SpringCore

Create a new DefaultResourceLoader.

Parameters
classLoader 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 Methods

public ClassLoader getClassLoader ()

Also: SpringCore

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.

Returns
  • the ClassLoader (never null)

public Resource getResource (String location)

Also: SpringCore

Return a Resource handle for the specified resource. The handle should always be a reusable resource descriptor, allowing for multiple 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 exists() to check for existence.

Parameters
location the resource location
Returns
  • a corresponding Resource handle

public void setClassLoader (ClassLoader classLoader)

Also: SpringCore

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.

The default is that ClassLoader access will happen using the thread context class loader at the time of this ResourceLoader's initialization.

Protected Methods

protected Resource getResourceByPath (String path)

Also: SpringCore

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