public class ResourcePropertySource extends PropertiesPropertySource
PropertiesPropertySource
that loads a Properties
object
from a given 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"
.
Resource
,
EncodedResource
PropertySource.StubPropertySource
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
resourceName
The original resource name, if different from the given name.
|
logger, name, source
Modifier | Constructor and Description |
---|---|
|
ResourcePropertySource(EncodedResource resource)
Create a PropertySource based on Properties loaded from the given resource.
|
|
ResourcePropertySource(Resource resource)
Create a PropertySource based on Properties loaded from the given resource.
|
|
ResourcePropertySource(java.lang.String location)
Create a PropertySource based on Properties loaded from the given resource
location.
|
|
ResourcePropertySource(java.lang.String location,
java.lang.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: . |
|
ResourcePropertySource(java.lang.String name,
EncodedResource resource)
Create a PropertySource having the given name based on Properties
loaded from the given encoded resource.
|
|
ResourcePropertySource(java.lang.String name,
Resource resource)
Create a PropertySource having the given name based on Properties
loaded from the given encoded resource.
|
|
ResourcePropertySource(java.lang.String name,
java.lang.String location)
Create a PropertySource having the given name based on Properties loaded from
the given resource location.
|
|
ResourcePropertySource(java.lang.String name,
java.lang.String location,
java.lang.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: ). |
private |
ResourcePropertySource(java.lang.String name,
java.lang.String resourceName,
java.util.Map<java.lang.String,java.lang.Object> source) |
Modifier and Type | Method and Description |
---|---|
private static java.lang.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.
|
ResourcePropertySource |
withName(java.lang.String name)
Return a potentially adapted variant of this
ResourcePropertySource ,
overriding the previously given (or derived) name with the specified name. |
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). |
containsProperty, getProperty, getPropertyNames
@Nullable private final java.lang.String resourceName
public ResourcePropertySource(java.lang.String name, EncodedResource resource) throws java.io.IOException
java.io.IOException
public ResourcePropertySource(EncodedResource resource) throws java.io.IOException
description
of the given resource.java.io.IOException
public ResourcePropertySource(java.lang.String name, Resource resource) throws java.io.IOException
java.io.IOException
public ResourcePropertySource(Resource resource) throws java.io.IOException
description
of the given resource.java.io.IOException
public ResourcePropertySource(java.lang.String name, java.lang.String location, java.lang.ClassLoader classLoader) throws java.io.IOException
classpath:
).java.io.IOException
public ResourcePropertySource(java.lang.String location, java.lang.ClassLoader classLoader) throws java.io.IOException
classpath:
. The name of the PropertySource will be
generated based on the description
of the
resource.java.io.IOException
public ResourcePropertySource(java.lang.String name, java.lang.String location) throws java.io.IOException
classpath:
.java.io.IOException
public ResourcePropertySource(java.lang.String location) throws java.io.IOException
description
of the resource.java.io.IOException
private ResourcePropertySource(java.lang.String name, @Nullable java.lang.String resourceName, java.util.Map<java.lang.String,java.lang.Object> source)
public ResourcePropertySource withName(java.lang.String name)
ResourcePropertySource
,
overriding the previously given (or derived) name with the specified name.public ResourcePropertySource withResourceName()
ResourcePropertySource
,
overriding the previously given name (if any) with the original resource name
(equivalent to the name generated by the name-less constructor variants).private static java.lang.String getNameForResource(Resource resource)
Resource.getDescription()