Top Description Fields Constructors Methods
org.springframework.beans.factory.support

public Class PropertiesBeanDefinitionReader

extends AbstractBeanDefinitionReader
Class Inheritance
Annotations
@Deprecated
Imports
java.io.IOException, .InputStream, .InputStreamReader, java.util.Enumeration, .HashMap, .Map, .Properties, .ResourceBundle, org.springframework.beans.BeansException, .MutablePropertyValues, .PropertyAccessor, org.springframework.beans.factory.BeanDefinitionStoreException, .CannotLoadBeanClassException, org.springframework.beans.factory.config.BeanDefinition, .ConstructorArgumentValues, .RuntimeBeanReference, org.springframework.core.io.Resource, org.springframework.core.io.support.EncodedResource, org.springframework.lang.Nullable, org.springframework.util.DefaultPropertiesPersister, .PropertiesPersister, .StringUtils

Deprecated

as of 5.3, in favor of Spring's common bean definition formats and/or custom reader implementations

Bean definition reader for a simple properties format.

Provides bean definition registration methods for Map/Properties and ResourceBundle. Typically applied to a DefaultListableBeanFactory.

Example:

employee.(class)=MyClass       // bean is of class MyClass
employee.(abstract)=true       // this bean can't be instantiated directly
employee.group=Insurance       // real property
employee.usesDialUp=false      // real property (potentially overridden)

salesrep.(parent)=employee     // derives from "employee" bean definition
salesrep.(lazy-init)=true      // lazily initialize this singleton bean
salesrep.manager(ref)=tony     // reference to another bean
salesrep.department=Sales      // real property

techie.(parent)=employee       // derives from "employee" bean definition
techie.(scope)=prototype       // bean is a prototype (not a shared instance)
techie.manager(ref)=jeff       // reference to another bean
techie.department=Engineering  // real property
techie.usesDialUp=true         // real property (overriding parent value)

ceo.$0(ref)=secretary          // inject 'secretary' bean as 0th constructor arg
ceo.$1=1000000                 // inject value '1000000' at 1st constructor arg
Authors
Rod Johnson, Juergen Hoeller, Rob Harrop
Since
26.11.2003
See Also
DefaultListableBeanFactory

Field Summary

Modifier and TypeField and Description
public static final String
ABSTRACT_KEY

Special key to distinguish owner.(abstract)=true Default is "false".

public static final String
CLASS_KEY

Special key to distinguish owner.(class)=com.myapp.MyClass.

public static final String
CONSTRUCTOR_ARG_PREFIX

Prefix used to denote a constructor argument definition.

private String
public static final String
LAZY_INIT_KEY

Special key to distinguish owner.(lazy-init)=true Default is "false".

public static final String
PARENT_KEY

Special key to distinguish owner.(parent)=parentBeanName.

private PropertiesPersister
public static final String
REF_PREFIX

Prefix before values referencing other beans.

public static final String
REF_SUFFIX

Property suffix for references to other beans in the current BeanFactory: e.g. owner.dog(ref)=fido.

public static final String
SCOPE_KEY

Special key to distinguish owner.(scope)=prototype.

public static final String
SEPARATOR

Separator between bean name and property name.

public static final String
SINGLETON_KEY

Special key to distinguish owner.(singleton)=false.

public static final String
TRUE_VALUE

Value of a T/F attribute that represents true.

Inherited from org.springframework.beans.factory.support.AbstractBeanDefinitionReader:
logger

Constructor Summary

AccessConstructor and Description
public
PropertiesBeanDefinitionReader(BeanDefinitionRegistry
the BeanFactory to load bean definitions into, in the form of a BeanDefinitionRegistry
registry
)

Create new PropertiesBeanDefinitionReader for the given bean factory.

Method Summary

Modifier and TypeMethod and Description
public String
getDefaultParentBean()

Return the default parent bean for this bean factory.

public PropertiesPersister
getPropertiesPersister()

Return the PropertiesPersister to use for parsing properties files.

public int

Returns:

the number of bean definitions found
loadBeanDefinitions
(Resource
the resource descriptor for the properties file
resource
)

Implements org.springframework.beans.factory.support.BeanDefinitionReader.loadBeanDefinitions.

Load bean definitions from the specified properties file, using all property keys (i.e. not filtering by prefix).

public int

Returns:

the number of bean definitions found
loadBeanDefinitions
(Resource
the resource descriptor for the properties file
resource
,
String
a filter within the keys in the map: e.g. 'beans.' (can be empty or null)
prefix
)

Load bean definitions from the specified properties file.

public int

Returns:

the number of bean definitions found
loadBeanDefinitions
(EncodedResource
the resource descriptor for the properties file, allowing to specify an encoding to use for parsing the file
encodedResource
)

Load bean definitions from the specified properties file.

public int

Returns:

the number of bean definitions found
loadBeanDefinitions
(EncodedResource
the resource descriptor for the properties file, allowing to specify an encoding to use for parsing the file
encodedResource
,
String
a filter within the keys in the map: e.g. 'beans.' (can be empty or null)
prefix
)

Load bean definitions from the specified properties file.

private Object
readValue(Map.Entry<?, ?> entry)

Reads the value of the entry.

protected void
registerBeanDefinition(String
name of the bean to define
beanName
,
Map<?, ?>
a Map containing string pairs
map
,
String
prefix of each entry, which will be stripped
prefix
,
String
description of the resource that the Map came from (for logging purposes)
resourceDescription
)

Get all property values, given a prefix (which will be stripped) and add the bean they define to the factory with the given name.

public int

Returns:

the number of bean definitions found
registerBeanDefinitions
(ResourceBundle
the ResourceBundle to load from
rb
)

Register bean definitions contained in a resource bundle, using all property keys (i.e. not filtering by prefix).

public int

Returns:

the number of bean definitions found
registerBeanDefinitions
(ResourceBundle
the ResourceBundle to load from
rb
,
String
a filter within the keys in the map: e.g. 'beans.' (can be empty or null)
prefix
)

Register bean definitions contained in a ResourceBundle.

public int

Returns:

the number of bean definitions found
registerBeanDefinitions
(Map<?, ?>
a map of name to property (String or Object). Property values will be strings if coming from a Properties file etc. Property names (keys) must be Strings. Class keys must be Strings.
map
)

Register bean definitions contained in a Map, using all property keys (i.e. not filtering by prefix).

public int

Returns:

the number of bean definitions found
registerBeanDefinitions
(Map<?, ?>
a map of name to property (String or Object). Property values will be strings if coming from a Properties file etc. Property names (keys) must be Strings. Class keys must be Strings.
map
,
String
a filter within the keys in the map: e.g. 'beans.' (can be empty or null)
prefix
)

Register bean definitions contained in a Map.

public int

Returns:

the number of bean definitions found
registerBeanDefinitions
(Map<?, ?>
a map of name to property (String or Object). Property values will be strings if coming from a Properties file etc. Property names (keys) must be Strings. Class keys must be Strings.
map
,
String
a filter within the keys in the map: e.g. 'beans.' (can be empty or null)
prefix
,
String
description of the resource that the Map came from (for logging purposes)
resourceDescription
)

Register bean definitions contained in a Map.

public void
setDefaultParentBean(String defaultParentBean)

Set the default parent bean for this bean factory.

public void
setPropertiesPersister(PropertiesPersister propertiesPersister)

Set the PropertiesPersister to use for parsing properties files.

Inherited from org.springframework.beans.factory.support.AbstractBeanDefinitionReader:
getBeanClassLoadergetBeanNameGeneratorgetEnvironmentgetRegistrygetResourceLoaderloadBeanDefinitionsloadBeanDefinitionsloadBeanDefinitionsloadBeanDefinitionssetBeanClassLoadersetBeanNameGeneratorsetEnvironmentsetResourceLoader

Field Detail

ABSTRACT_KEYback to summary
public static final String ABSTRACT_KEY

Special key to distinguish owner.(abstract)=true Default is "false".

CLASS_KEYback to summary
public static final String CLASS_KEY

Special key to distinguish owner.(class)=com.myapp.MyClass.

CONSTRUCTOR_ARG_PREFIXback to summary
public static final String CONSTRUCTOR_ARG_PREFIX

Prefix used to denote a constructor argument definition.

defaultParentBeanback to summary
private String defaultParentBean
Annotations
@Nullable
LAZY_INIT_KEYback to summary
public static final String LAZY_INIT_KEY

Special key to distinguish owner.(lazy-init)=true Default is "false".

PARENT_KEYback to summary
public static final String PARENT_KEY

Special key to distinguish owner.(parent)=parentBeanName.

propertiesPersisterback to summary
private PropertiesPersister propertiesPersister
REF_PREFIXback to summary
public static final String REF_PREFIX

Prefix before values referencing other beans.

REF_SUFFIXback to summary
public static final String REF_SUFFIX

Property suffix for references to other beans in the current BeanFactory: e.g. owner.dog(ref)=fido. Whether this is a reference to a singleton or a prototype will depend on the definition of the target bean.

SCOPE_KEYback to summary
public static final String SCOPE_KEY

Special key to distinguish owner.(scope)=prototype. Default is "true".

SEPARATORback to summary
public static final String SEPARATOR

Separator between bean name and property name. We follow normal Java conventions.

SINGLETON_KEYback to summary
public static final String SINGLETON_KEY

Special key to distinguish owner.(singleton)=false. Default is "true".

TRUE_VALUEback to summary
public static final String TRUE_VALUE

Value of a T/F attribute that represents true. Anything else represents false. Case seNsItive.

Constructor Detail

PropertiesBeanDefinitionReaderback to summary
public PropertiesBeanDefinitionReader(BeanDefinitionRegistry registry)

Create new PropertiesBeanDefinitionReader for the given bean factory.

Parameters
registry:BeanDefinitionRegistry

the BeanFactory to load bean definitions into, in the form of a BeanDefinitionRegistry

Method Detail

getDefaultParentBeanback to summary
public String getDefaultParentBean()

Return the default parent bean for this bean factory.

Annotations
@Nullable
getPropertiesPersisterback to summary
public PropertiesPersister getPropertiesPersister()

Return the PropertiesPersister to use for parsing properties files.

loadBeanDefinitionsback to summary
public int loadBeanDefinitions(Resource resource) throws BeanDefinitionStoreException

Implements org.springframework.beans.factory.support.BeanDefinitionReader.loadBeanDefinitions.

Load bean definitions from the specified properties file, using all property keys (i.e. not filtering by prefix).

Parameters
resource:Resource

the resource descriptor for the properties file

Returns:int

the number of bean definitions found

Annotations
@Override
Exceptions
BeanDefinitionStoreException:
in case of loading or parsing errors
See Also
loadBeanDefinitions(org.springframework.core.io.Resource, String)
loadBeanDefinitionsback to summary
public int loadBeanDefinitions(Resource resource, String prefix) throws BeanDefinitionStoreException

Load bean definitions from the specified properties file.

Parameters
resource:Resource

the resource descriptor for the properties file

prefix:String

a filter within the keys in the map: e.g. 'beans.' (can be empty or null)

Returns:int

the number of bean definitions found

Exceptions
BeanDefinitionStoreException:
in case of loading or parsing errors
loadBeanDefinitionsback to summary
public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException

Load bean definitions from the specified properties file.

Parameters
encodedResource:EncodedResource

the resource descriptor for the properties file, allowing to specify an encoding to use for parsing the file

Returns:int

the number of bean definitions found

Exceptions
BeanDefinitionStoreException:
in case of loading or parsing errors
loadBeanDefinitionsback to summary
public int loadBeanDefinitions(EncodedResource encodedResource, String prefix) throws BeanDefinitionStoreException

Load bean definitions from the specified properties file.

Parameters
encodedResource:EncodedResource

the resource descriptor for the properties file, allowing to specify an encoding to use for parsing the file

prefix:String

a filter within the keys in the map: e.g. 'beans.' (can be empty or null)

Returns:int

the number of bean definitions found

Exceptions
BeanDefinitionStoreException:
in case of loading or parsing errors
readValueback to summary
private Object readValue(Map.Entry<?, ?> entry)

Reads the value of the entry. Correctly interprets bean references for values that are prefixed with an asterisk.

registerBeanDefinitionback to summary
protected void registerBeanDefinition(String beanName, Map<?, ?> map, String prefix, String resourceDescription) throws BeansException

Get all property values, given a prefix (which will be stripped) and add the bean they define to the factory with the given name.

Parameters
beanName:String

name of the bean to define

map:Map<?, ?>

a Map containing string pairs

prefix:String

prefix of each entry, which will be stripped

resourceDescription:String

description of the resource that the Map came from (for logging purposes)

Exceptions
BeansException:
if the bean definition could not be parsed or registered
registerBeanDefinitionsback to summary
public int registerBeanDefinitions(ResourceBundle rb) throws BeanDefinitionStoreException

Register bean definitions contained in a resource bundle, using all property keys (i.e. not filtering by prefix).

Parameters
rb:ResourceBundle

the ResourceBundle to load from

Returns:int

the number of bean definitions found

Exceptions
BeanDefinitionStoreException:
in case of loading or parsing errors
See Also
registerBeanDefinitions(java.util.ResourceBundle, String)
registerBeanDefinitionsback to summary
public int registerBeanDefinitions(ResourceBundle rb, String prefix) throws BeanDefinitionStoreException

Register bean definitions contained in a ResourceBundle.

Similar syntax as for a Map. This method is useful to enable standard Java internationalization support.

Parameters
rb:ResourceBundle

the ResourceBundle to load from

prefix:String

a filter within the keys in the map: e.g. 'beans.' (can be empty or null)

Returns:int

the number of bean definitions found

Exceptions
BeanDefinitionStoreException:
in case of loading or parsing errors
registerBeanDefinitionsback to summary
public int registerBeanDefinitions(Map<?, ?> map) throws BeansException

Register bean definitions contained in a Map, using all property keys (i.e. not filtering by prefix).

Parameters
map:Map<?, ?>

a map of name to property (String or Object). Property values will be strings if coming from a Properties file etc. Property names (keys) must be Strings. Class keys must be Strings.

Returns:int

the number of bean definitions found

Exceptions
BeansException:
in case of loading or parsing errors
See Also
registerBeanDefinitions(java.util.Map, String, String)
registerBeanDefinitionsback to summary
public int registerBeanDefinitions(Map<?, ?> map, String prefix) throws BeansException

Register bean definitions contained in a Map. Ignore ineligible properties.

Parameters
map:Map<?, ?>

a map of name to property (String or Object). Property values will be strings if coming from a Properties file etc. Property names (keys) must be Strings. Class keys must be Strings.

prefix:String

a filter within the keys in the map: e.g. 'beans.' (can be empty or null)

Returns:int

the number of bean definitions found

Exceptions
BeansException:
in case of loading or parsing errors
registerBeanDefinitionsback to summary
public int registerBeanDefinitions(Map<?, ?> map, String prefix, String resourceDescription) throws BeansException

Register bean definitions contained in a Map. Ignore ineligible properties.

Parameters
map:Map<?, ?>

a map of name to property (String or Object). Property values will be strings if coming from a Properties file etc. Property names (keys) must be Strings. Class keys must be Strings.

prefix:String

a filter within the keys in the map: e.g. 'beans.' (can be empty or null)

resourceDescription:String

description of the resource that the Map came from (for logging purposes)

Returns:int

the number of bean definitions found

Exceptions
BeansException:
in case of loading or parsing errors
See Also
registerBeanDefinitions(Map, String)
setDefaultParentBeanback to summary
public void setDefaultParentBean(String defaultParentBean)

Set the default parent bean for this bean factory. If a child bean definition handled by this factory provides neither a parent nor a class attribute, this default value gets used.

Can be used e.g. for view definition files, to define a parent with a default view class and common attributes for all views. View definitions that define their own parent or carry their own class can still override this.

Strictly speaking, the rule that a default parent setting does not apply to a bean definition that carries a class is there for backwards compatibility reasons. It still matches the typical use case.

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