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

public abstract Class PropertiesLoaderSupport

extends Object
Class Inheritance
Imports
java.io.FileNotFoundException, .IOException, java.net.SocketException, .UnknownHostException, java.util.Properties, org.apache.commons.logging.Log, .LogFactory, org.springframework.core.io.Resource, org.springframework.lang.Nullable, org.springframework.util.CollectionUtils, .DefaultPropertiesPersister, .PropertiesPersister

Base class for JavaBean-style components that need to load properties from one or more resources. Supports local properties as well, with configurable overriding.
Author
Juergen Hoeller
Since
1.2.2

Field Summary

Modifier and TypeField and Description
private String
private boolean
protected boolean
protected Properties[]
private Resource[]
protected final Log
logger

Logger available to subclasses.

private PropertiesPersister

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
loadProperties(Properties
the Properties instance to load into
props
)

Load properties into the given instance.

protected Properties
mergeProperties()

Return a merged Properties instance containing both the loaded properties and properties set on this FactoryBean.

public void
setFileEncoding(String encoding)

Set the encoding to use for parsing properties files.

public void
setIgnoreResourceNotFound(boolean ignoreResourceNotFound)

Set if failure to find the property resource should be ignored.

public void
setLocalOverride(boolean localOverride)

Set whether local properties override properties from files.

public void
setLocation(Resource location)

Set a location of a properties file to be loaded.

public void
setLocations(Resource... locations)

Set locations of properties files to be loaded.

public void
setProperties(Properties properties)

Set local properties, e.g. via the "props" tag in XML bean definitions.

public void
setPropertiesArray(Properties... propertiesArray)

Set local properties, e.g. via the "props" tag in XML bean definitions, allowing for merging multiple properties sets into one.

public void
setPropertiesPersister(PropertiesPersister propertiesPersister)

Set the PropertiesPersister to use for parsing properties files.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fileEncodingback to summary
private String fileEncoding
Annotations
@Nullable
ignoreResourceNotFoundback to summary
private boolean ignoreResourceNotFound
localOverrideback to summary
protected boolean localOverride
localPropertiesback to summary
protected Properties[] localProperties
Annotations
@Nullable
locationsback to summary
private Resource[] locations
Annotations
@Nullable
loggerback to summary
protected final Log logger

Logger available to subclasses.

propertiesPersisterback to summary
private PropertiesPersister propertiesPersister

Constructor Detail

PropertiesLoaderSupportback to summary
public PropertiesLoaderSupport()

Method Detail

loadPropertiesback to summary
protected void loadProperties(Properties props) throws IOException

Load properties into the given instance.

Parameters
props:Properties

the Properties instance to load into

Exceptions
IOException:
in case of I/O errors
See Also
setLocations
mergePropertiesback to summary
protected Properties mergeProperties() throws IOException

Return a merged Properties instance containing both the loaded properties and properties set on this FactoryBean.

setFileEncodingback to summary
public void setFileEncoding(String encoding)

Set the encoding to use for parsing properties files.

Default is none, using the java.util.Properties default encoding.

Only applies to classic properties files, not to XML files.

See Also
org.springframework.util.PropertiesPersister#load
setIgnoreResourceNotFoundback to summary
public void setIgnoreResourceNotFound(boolean ignoreResourceNotFound)

Set if failure to find the property resource should be ignored.

"true" is appropriate if the properties file is completely optional. Default is "false".

setLocalOverrideback to summary
public void setLocalOverride(boolean localOverride)

Set whether local properties override properties from files.

Default is "false": Properties from files override local defaults. Can be switched to "true" to let local properties override defaults from files.

setLocationback to summary
public void setLocation(Resource location)

Set a location of a properties file to be loaded.

Can point to a classic properties file or to an XML file that follows JDK 1.5's properties XML format.

setLocationsback to summary
public void setLocations(Resource... locations)

Set locations of properties files to be loaded.

Can point to classic properties files or to XML files that follow JDK 1.5's properties XML format.

Note

Properties defined in later files will override properties defined earlier files, in case of overlapping keys. Hence, make sure that the most specific files are the last ones in the given list of locations.

setPropertiesback to summary
public void setProperties(Properties properties)

Set local properties, e.g. via the "props" tag in XML bean definitions. These can be considered defaults, to be overridden by properties loaded from files.

setPropertiesArrayback to summary
public void setPropertiesArray(Properties... propertiesArray)

Set local properties, e.g. via the "props" tag in XML bean definitions, allowing for merging multiple properties sets into one.

setPropertiesPersisterback to summary
public void setPropertiesPersister(PropertiesPersister propertiesPersister)

Set the PropertiesPersister to use for parsing properties files. The default is DefaultPropertiesPersister.

See Also
DefaultPropertiesPersister#INSTANCE