spring-framework / org.springframework.beans.factory.support / PropertiesBeanDefinitionReader

PropertiesBeanDefinitionReader

open class PropertiesBeanDefinitionReader : 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 

Author
Rod Johnson

Author
Juergen Hoeller

Author
Rob Harrop

Since
26.11.2003

See Also
DefaultListableBeanFactory

Constructors

<init>

PropertiesBeanDefinitionReader(registry: BeanDefinitionRegistry)

Create new PropertiesBeanDefinitionReader for the given bean factory.

Properties

ABSTRACT_KEY

static val ABSTRACT_KEY: String

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

CLASS_KEY

static val CLASS_KEY: String

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

CONSTRUCTOR_ARG_PREFIX

static val CONSTRUCTOR_ARG_PREFIX: String

Prefix used to denote a constructor argument definition.

LAZY_INIT_KEY

static val LAZY_INIT_KEY: String

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

PARENT_KEY

static val PARENT_KEY: String

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

REF_PREFIX

static val REF_PREFIX: String

Prefix before values referencing other beans.

REF_SUFFIX

static val REF_SUFFIX: String

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_KEY

static val SCOPE_KEY: String

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

SEPARATOR

static val SEPARATOR: String

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

SINGLETON_KEY

static val SINGLETON_KEY: String

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

TRUE_VALUE

static val TRUE_VALUE: String

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

Functions

getDefaultParentBean

open fun getDefaultParentBean(): String

Return the default parent bean for this bean factory.

getPropertiesPersister

open fun getPropertiesPersister(): PropertiesPersister

Return the PropertiesPersister to use for parsing properties files.

loadBeanDefinitions

open fun loadBeanDefinitions(resource: Resource): Int

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

open fun loadBeanDefinitions(resource: Resource, prefix: String): Int
open fun loadBeanDefinitions(encodedResource: EncodedResource): Int
open fun loadBeanDefinitions(encodedResource: EncodedResource, prefix: String): Int

Load bean definitions from the specified properties file.

registerBeanDefinitions

open fun registerBeanDefinitions(rb: ResourceBundle): Int

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

open fun registerBeanDefinitions(rb: ResourceBundle, prefix: String): Int

Register bean definitions contained in a ResourceBundle.

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

open fun registerBeanDefinitions(map: MutableMap<*, *>): Int

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

open fun registerBeanDefinitions(map: MutableMap<*, *>, prefix: String): Int
open fun registerBeanDefinitions(map: MutableMap<*, *>, prefix: String, resourceDescription: String): Int

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

setDefaultParentBean

open fun setDefaultParentBean(defaultParentBean: String): Unit

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.

setPropertiesPersister

open fun setPropertiesPersister(propertiesPersister: PropertiesPersister): Unit

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

Inherited Functions

getBeanClassLoader

open fun getBeanClassLoader(): ClassLoader

getBeanFactory

fun getBeanFactory(): BeanDefinitionRegistry

getBeanNameGenerator

open fun getBeanNameGenerator(): BeanNameGenerator

getEnvironment

open fun getEnvironment(): Environment

getRegistry

fun getRegistry(): BeanDefinitionRegistry

getResourceLoader

open fun getResourceLoader(): ResourceLoader

loadBeanDefinitions

open fun loadBeanDefinitions(vararg resources: Resource): Int
open fun loadBeanDefinitions(location: String): Int
open fun loadBeanDefinitions(vararg locations: String): Intopen fun loadBeanDefinitions(location: String, actualResources: MutableSet<Resource>): Int

Load bean definitions from the specified resource location.

The location can also be a location pattern, provided that the ResourceLoader of this bean definition reader is a ResourcePatternResolver.

setBeanClassLoader

open fun setBeanClassLoader(beanClassLoader: ClassLoader): Unit

Set the ClassLoader to use for bean classes.

Default is null, which suggests to not load bean classes eagerly but rather to just register bean definitions with class names, with the corresponding Classes to be resolved later (or never).

setBeanNameGenerator

open fun setBeanNameGenerator(beanNameGenerator: BeanNameGenerator): Unit

Set the BeanNameGenerator to use for anonymous beans (without explicit bean name specified).

Default is a DefaultBeanNameGenerator.

setEnvironment

open fun setEnvironment(environment: Environment): Unit

Set the Environment to use when reading bean definitions. Most often used for evaluating profile information to determine which bean definitions should be read and which should be omitted.

setResourceLoader

open fun setResourceLoader(resourceLoader: ResourceLoader): Unit

Set the ResourceLoader to use for resource locations. If specifying a ResourcePatternResolver, the bean definition reader will be capable of resolving resource patterns to Resource arrays.

Default is PathMatchingResourcePatternResolver, also capable of resource pattern resolving through the ResourcePatternResolver interface.

Setting this to null suggests that absolute resource loading is not available for this bean definition reader.