类 PropertiesBeanDefinitionReader
- java.lang.Object
- org.springframework.beans.factory.support.AbstractBeanDefinitionReader
- org.springframework.beans.factory.support.PropertiesBeanDefinitionReader
- 所有已实现的接口:
BeanDefinitionReader
,EnvironmentCapable
public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader
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
- 从以下版本开始:
- 26.11.2003
- 作者:
- Rod Johnson, Juergen Hoeller, Rob Harrop
- 另请参阅:
DefaultListableBeanFactory
字段概要
字段 修饰符和类型 字段 说明 static String
ABSTRACT_KEY
Special key to distinguishowner.(abstract)=true
Default is "false".static String
CLASS_KEY
Special key to distinguishowner.(class)=com.myapp.MyClass
.static String
CONSTRUCTOR_ARG_PREFIX
Prefix used to denote a constructor argument definition.static String
LAZY_INIT_KEY
Special key to distinguishowner.(lazy-init)=true
Default is "false".static String
PARENT_KEY
Special key to distinguishowner.(parent)=parentBeanName
.static String
REF_PREFIX
Prefix before values referencing other beans.static String
REF_SUFFIX
Property suffix for references to other beans in the current BeanFactory: e.g.static String
SCOPE_KEY
Special key to distinguishowner.(scope)=prototype
.static String
SEPARATOR
Separator between bean name and property name.static String
SINGLETON_KEY
Special key to distinguishowner.(singleton)=false
.static String
TRUE_VALUE
Value of a T/F attribute that represents true.从类继承的字段 org.springframework.beans.factory.support.AbstractBeanDefinitionReader
logger
构造器概要
构造器 构造器 说明 PropertiesBeanDefinitionReader(BeanDefinitionRegistry registry)
Create new PropertiesBeanDefinitionReader for the given bean factory.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 String
getDefaultParentBean()
Return the default parent bean for this bean factory.PropertiesPersister
getPropertiesPersister()
Return the PropertiesPersister to use for parsing properties files.int
loadBeanDefinitions(Resource resource)
Load bean definitions from the specified properties file, using all property keys (i.e. not filtering by prefix).int
loadBeanDefinitions(Resource resource, String prefix)
Load bean definitions from the specified properties file.int
loadBeanDefinitions(EncodedResource encodedResource)
Load bean definitions from the specified properties file.int
loadBeanDefinitions(EncodedResource encodedResource, String prefix)
Load bean definitions from the specified properties file.protected void
registerBeanDefinition(String beanName, Map<?,?> map, String prefix, String 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.int
registerBeanDefinitions(Map<?,?> map)
Register bean definitions contained in a Map, using all property keys (i.e. not filtering by prefix).int
registerBeanDefinitions(Map<?,?> map, String prefix)
Register bean definitions contained in a Map.int
registerBeanDefinitions(Map<?,?> map, String prefix, String resourceDescription)
Register bean definitions contained in a Map.int
registerBeanDefinitions(ResourceBundle rb)
Register bean definitions contained in a resource bundle, using all property keys (i.e. not filtering by prefix).int
registerBeanDefinitions(ResourceBundle rb, String prefix)
Register bean definitions contained in a ResourceBundle.void
setDefaultParentBean(String defaultParentBean)
Set the default parent bean for this bean factory.void
setPropertiesPersister(PropertiesPersister propertiesPersister)
Set the PropertiesPersister to use for parsing properties files.从类继承的方法 org.springframework.beans.factory.support.AbstractBeanDefinitionReader
getBeanClassLoader, getBeanFactory, getBeanNameGenerator, getEnvironment, getRegistry, getResourceLoader, loadBeanDefinitions, loadBeanDefinitions, loadBeanDefinitions, loadBeanDefinitions, setBeanClassLoader, setBeanNameGenerator, setEnvironment, setResourceLoader
字段详细资料
TRUE_VALUE
public static final String TRUE_VALUE
Value of a T/F attribute that represents true. Anything else represents false. Case seNsItive.- 另请参阅:
- 常量字段值
SEPARATOR
public static final String SEPARATOR
Separator between bean name and property name. We follow normal Java conventions.- 另请参阅:
- 常量字段值
CLASS_KEY
public static final String CLASS_KEY
Special key to distinguishowner.(class)=com.myapp.MyClass
.- 另请参阅:
- 常量字段值
PARENT_KEY
public static final String PARENT_KEY
Special key to distinguishowner.(parent)=parentBeanName
.- 另请参阅:
- 常量字段值
SCOPE_KEY
public static final String SCOPE_KEY
Special key to distinguishowner.(scope)=prototype
. Default is "true".- 另请参阅:
- 常量字段值
SINGLETON_KEY
public static final String SINGLETON_KEY
Special key to distinguishowner.(singleton)=false
. Default is "true".- 另请参阅:
- 常量字段值
ABSTRACT_KEY
public static final String ABSTRACT_KEY
Special key to distinguishowner.(abstract)=true
Default is "false".- 另请参阅:
- 常量字段值
LAZY_INIT_KEY
public static final String LAZY_INIT_KEY
Special key to distinguishowner.(lazy-init)=true
Default is "false".- 另请参阅:
- 常量字段值
REF_SUFFIX
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.- 另请参阅:
- 常量字段值
REF_PREFIX
public static final String REF_PREFIX
Prefix before values referencing other beans.- 另请参阅:
- 常量字段值
CONSTRUCTOR_ARG_PREFIX
public static final String CONSTRUCTOR_ARG_PREFIX
Prefix used to denote a constructor argument definition.- 另请参阅:
- 常量字段值
构造器详细资料
PropertiesBeanDefinitionReader
public PropertiesBeanDefinitionReader(BeanDefinitionRegistry registry)
Create new PropertiesBeanDefinitionReader for the given bean factory.- 参数:
registry
- the BeanFactory to load bean definitions into, in the form of a BeanDefinitionRegistry
方法详细资料
setDefaultParentBean
public void setDefaultParentBean(@Nullable 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.
getDefaultParentBean
@Nullable public String getDefaultParentBean()
Return the default parent bean for this bean factory.
setPropertiesPersister
public void setPropertiesPersister(@Nullable PropertiesPersister propertiesPersister)
Set the PropertiesPersister to use for parsing properties files. The default is DefaultPropertiesPersister.
getPropertiesPersister
public PropertiesPersister getPropertiesPersister()
Return the PropertiesPersister to use for parsing properties files.
loadBeanDefinitions
public int loadBeanDefinitions(Resource resource) throws BeanDefinitionStoreException
Load bean definitions from the specified properties file, using all property keys (i.e. not filtering by prefix).- 参数:
resource
- the resource descriptor for the properties file- 返回:
- the number of bean definitions found
- 抛出:
BeanDefinitionStoreException
- in case of loading or parsing errors- 另请参阅:
loadBeanDefinitions(org.springframework.core.io.Resource, String)
loadBeanDefinitions
public int loadBeanDefinitions(Resource resource, @Nullable String prefix) throws BeanDefinitionStoreException
Load bean definitions from the specified properties file.- 参数:
resource
- the resource descriptor for the properties fileprefix
- a filter within the keys in the map: e.g. 'beans.' (can be empty ornull
)- 返回:
- the number of bean definitions found
- 抛出:
BeanDefinitionStoreException
- in case of loading or parsing errors
loadBeanDefinitions
public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException
Load bean definitions from the specified properties file.- 参数:
encodedResource
- the resource descriptor for the properties file, allowing to specify an encoding to use for parsing the file- 返回:
- the number of bean definitions found
- 抛出:
BeanDefinitionStoreException
- in case of loading or parsing errors
loadBeanDefinitions
public int loadBeanDefinitions(EncodedResource encodedResource, @Nullable String prefix) throws BeanDefinitionStoreException
Load bean definitions from the specified properties file.- 参数:
encodedResource
- the resource descriptor for the properties file, allowing to specify an encoding to use for parsing the fileprefix
- a filter within the keys in the map: e.g. 'beans.' (can be empty ornull
)- 返回:
- the number of bean definitions found
- 抛出:
BeanDefinitionStoreException
- in case of loading or parsing errors
registerBeanDefinitions
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).- 参数:
rb
- the ResourceBundle to load from- 返回:
- the number of bean definitions found
- 抛出:
BeanDefinitionStoreException
- in case of loading or parsing errors- 另请参阅:
registerBeanDefinitions(java.util.ResourceBundle, String)
registerBeanDefinitions
public int registerBeanDefinitions(ResourceBundle rb, @Nullable 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.
- 参数:
rb
- the ResourceBundle to load fromprefix
- a filter within the keys in the map: e.g. 'beans.' (can be empty ornull
)- 返回:
- the number of bean definitions found
- 抛出:
BeanDefinitionStoreException
- in case of loading or parsing errors
registerBeanDefinitions
public int registerBeanDefinitions(Map<?,?> map) throws BeansException
Register bean definitions contained in a Map, using all property keys (i.e. not filtering by prefix).- 参数:
map
- a map ofname
toproperty
(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.- 返回:
- the number of bean definitions found
- 抛出:
BeansException
- in case of loading or parsing errors- 另请参阅:
registerBeanDefinitions(java.util.Map, String, String)
registerBeanDefinitions
public int registerBeanDefinitions(Map<?,?> map, @Nullable String prefix) throws BeansException
Register bean definitions contained in a Map. Ignore ineligible properties.- 参数:
map
- a map ofname
toproperty
(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
- a filter within the keys in the map: e.g. 'beans.' (can be empty ornull
)- 返回:
- the number of bean definitions found
- 抛出:
BeansException
- in case of loading or parsing errors
registerBeanDefinitions
public int registerBeanDefinitions(Map<?,?> map, @Nullable String prefix, String resourceDescription) throws BeansException
Register bean definitions contained in a Map. Ignore ineligible properties.- 参数:
map
- a map ofname
toproperty
(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
- a filter within the keys in the map: e.g. 'beans.' (can be empty ornull
)resourceDescription
- description of the resource that the Map came from (for logging purposes)- 返回:
- the number of bean definitions found
- 抛出:
BeansException
- in case of loading or parsing errors- 另请参阅:
registerBeanDefinitions(Map, String)
registerBeanDefinition
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.- 参数:
beanName
- name of the bean to definemap
- a Map containing string pairsprefix
- prefix of each entry, which will be strippedresourceDescription
- description of the resource that the Map came from (for logging purposes)- 抛出:
BeansException
- if the bean definition could not be parsed or registered