Top Description Fields Constructors Methods
org.springframework.core.io.support

public Class ResourcePropertySource

extends PropertiesPropertySource
Class Inheritance
Imports
java.io.IOException, java.util.Map, .Properties, org.springframework.core.env.PropertiesPropertySource, org.springframework.core.io.DefaultResourceLoader, .Resource, org.springframework.lang.Nullable, org.springframework.util.StringUtils

Subclass of PropertiesPropertySource that loads a Properties object from a given org.springframework.core.io.Resource or resource location such as "classpath:/com/myco/foo.properties" or "file:/path/to/file.xml".

Both traditional and XML-based properties file formats are supported; however, in order for XML processing to take effect, the underlying Resource's getFilename() method must return a non-null value that ends in ".xml".

Authors
Chris Beams, Juergen Hoeller
Since
3.1
See Also
org.springframework.core.io.Resource, org.springframework.core.io.support.EncodedResource

Field Summary

Modifier and TypeField and Description
private final String
resourceName

The original resource name, if different from the given name.

Constructor Summary

AccessConstructor and Description
public
ResourcePropertySource(String name, EncodedResource resource)

Create a PropertySource having the given name based on Properties loaded from the given encoded resource.

public
ResourcePropertySource(EncodedResource resource)

Create a PropertySource based on Properties loaded from the given resource.

public
ResourcePropertySource(String name, Resource resource)

Create a PropertySource having the given name based on Properties loaded from the given encoded resource.

public
ResourcePropertySource(Resource resource)

Create a PropertySource based on Properties loaded from the given resource.

public
ResourcePropertySource(String name, String location, ClassLoader classLoader)

Create a PropertySource having the given name based on Properties loaded from the given resource location and using the given class loader to load the resource (assuming it is prefixed with classpath:).

public
ResourcePropertySource(String location, ClassLoader classLoader)

Create a PropertySource based on Properties loaded from the given resource location and use the given class loader to load the resource, assuming it is prefixed with classpath:.

public
ResourcePropertySource(String name, String location)

Create a PropertySource having the given name based on Properties loaded from the given resource location.

public
ResourcePropertySource(String location)

Create a PropertySource based on Properties loaded from the given resource location.

private
ResourcePropertySource(String name, String resourceName, Map<String, Object> source)

Method Summary

Modifier and TypeMethod and Description
private static String
getNameForResource(Resource resource)

Return the description for the given Resource; if the description is empty, return the class name of the resource plus its identity hash code.

public ResourcePropertySource
withName(String name)

Return a potentially adapted variant of this ResourcePropertySource, overriding the previously given (or derived) name with the specified name.

public ResourcePropertySource
withResourceName()

Return a potentially adapted variant of this ResourcePropertySource, overriding the previously given name (if any) with the original resource name (equivalent to the name generated by the name-less constructor variants).

Inherited from org.springframework.core.env.PropertiesPropertySource:
getPropertyNames

Field Detail

resourceNameback to summary
private final String resourceName

The original resource name, if different from the given name.

Annotations
@Nullable

Constructor Detail

ResourcePropertySourceback to summary
public ResourcePropertySource(String name, EncodedResource resource) throws IOException

Create a PropertySource having the given name based on Properties loaded from the given encoded resource.

ResourcePropertySourceback to summary
public ResourcePropertySource(EncodedResource resource) throws IOException

Create a PropertySource based on Properties loaded from the given resource. The name of the PropertySource will be generated based on the description of the given resource.

ResourcePropertySourceback to summary
public ResourcePropertySource(String name, Resource resource) throws IOException

Create a PropertySource having the given name based on Properties loaded from the given encoded resource.

ResourcePropertySourceback to summary
public ResourcePropertySource(Resource resource) throws IOException

Create a PropertySource based on Properties loaded from the given resource. The name of the PropertySource will be generated based on the description of the given resource.

ResourcePropertySourceback to summary
public ResourcePropertySource(String name, String location, ClassLoader classLoader) throws IOException

Create a PropertySource having the given name based on Properties loaded from the given resource location and using the given class loader to load the resource (assuming it is prefixed with classpath:).

ResourcePropertySourceback to summary
public ResourcePropertySource(String location, ClassLoader classLoader) throws IOException

Create a PropertySource based on Properties loaded from the given resource location and use the given class loader to load the resource, assuming it is prefixed with classpath:. The name of the PropertySource will be generated based on the description of the resource.

ResourcePropertySourceback to summary
public ResourcePropertySource(String name, String location) throws IOException

Create a PropertySource having the given name based on Properties loaded from the given resource location. The default thread context class loader will be used to load the resource (assuming the location string is prefixed with classpath:).

ResourcePropertySourceback to summary
public ResourcePropertySource(String location) throws IOException

Create a PropertySource based on Properties loaded from the given resource location. The name of the PropertySource will be generated based on the description of the resource.

ResourcePropertySourceback to summary
private ResourcePropertySource(String name, String resourceName, Map<String, Object> source)

Method Detail

getNameForResourceback to summary
private static String getNameForResource(Resource resource)

Return the description for the given Resource; if the description is empty, return the class name of the resource plus its identity hash code.

See Also
org.springframework.core.io.Resource#getDescription()
withNameback to summary
public ResourcePropertySource withName(String name)

Return a potentially adapted variant of this ResourcePropertySource, overriding the previously given (or derived) name with the specified name.

Since
4.0.4
withResourceNameback to summary
public ResourcePropertySource withResourceName()

Return a potentially adapted variant of this ResourcePropertySource, overriding the previously given name (if any) with the original resource name (equivalent to the name generated by the name-less constructor variants).

Since
4.1