org.springframework.beans.factory.config
Class PropertiesFactoryBean


public class PropertiesFactoryBean
implements FactoryBean, InitializingBean

Allows for making a properties file from a classpath location available as Properties instance in a bean factory. Can be used for to populate any bean property of type Properties via a bean reference.

Supports loading from a properties file and/or setting local properties on this FactoryBean. The created Properties instance will be merged from loaded and local values. If neither a location nor local properties are set, an exception will be thrown on initialization.

Can create a singleton or a new object on each request. Default is singleton.

Author:
Juergen Hoeller
See Also: Properties

Method Summary
 voidafterPropertiesSet()
          Create a singleton instance on initialization if in singleton mode.
 ObjectgetObject()
          Return either singleton instance or newly created instance, depending on the singleton property of this FactoryBean.
 ClassgetObjectType()
           
 booleanisSingleton()
           
 voidsetLocation(Resource location)
          Set a location of a properties file to be loaded.
 voidsetLocations(Resource[] locations)
          Set locations of properties files to be loaded.
 voidsetProperties(Properties properties)
          Set local properties, e.g.
 voidsetSingleton(boolean singleton)
          Set if a singleton should be created, or a new object on each request else.

Method Detail

afterPropertiesSet

public void afterPropertiesSet()
throws java.io.IOException
Create a singleton instance on initialization if in singleton mode.

getObject

public Object getObject()
throws java.io.IOException
Return either singleton instance or newly created instance, depending on the singleton property of this FactoryBean. Delegates to mergeProperties for actual instance creation.
See Also:
mergeProperties()

getObjectType

public Class getObjectType()

isSingleton

public boolean isSingleton()

setLocation

public void setLocation(Resource location)
Set a location of a properties file to be loaded.

setLocations

public void setLocations(Resource[] locations)
Set locations of properties files to be loaded.

setProperties

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.

setSingleton

public void setSingleton(boolean singleton)
Set if a singleton should be created, or a new object on each request else. Default is true.

Association Links

to Class java.util.Properties

to Class org.springframework.core.io.Resource

to Class java.util.Properties