spring-framework / org.springframework.beans.factory.config / YamlPropertiesFactoryBean

YamlPropertiesFactoryBean

open class YamlPropertiesFactoryBean : YamlProcessor, FactoryBean<Properties>, InitializingBean

Factory for java.util.Properties that reads from a YAML source, exposing a flat structure of String property values.

YAML is a nice human-readable format for configuration, and it has some useful hierarchical properties. It's more or less a superset of JSON, so it has a lot of similar features.

Note: All exposed values are of type String for access through the common Properties#getProperty method (e.g. in configuration property resolution through PropertyResourceConfigurer#setProperties(Properties)). If this is not desirable, use YamlMapFactoryBean instead.

The Properties created by this factory have nested paths for hierarchical objects, so for instance this YAML

 environments: dev: url: http://dev.bar.com name: Developer Setup prod: url: http://foo.bar.com name: My Cool App 
is transformed into these properties:
 environments.dev.url=http://dev.bar.com environments.dev.name=Developer Setup environments.prod.url=http://foo.bar.com environments.prod.name=My Cool App 
Lists are split as property keys with [] dereferencers, for example this YAML:
 servers: - dev.bar.com - foo.bar.com 
becomes properties like this:
 servers[0]=dev.bar.com servers[1]=foo.bar.com 

Author
Dave Syer

Author
Stephane Nicoll

Author
Juergen Hoeller

Since
4.1

Constructors

<init>

YamlPropertiesFactoryBean()

Factory for java.util.Properties that reads from a YAML source, exposing a flat structure of String property values.

YAML is a nice human-readable format for configuration, and it has some useful hierarchical properties. It's more or less a superset of JSON, so it has a lot of similar features.

Note: All exposed values are of type String for access through the common Properties#getProperty method (e.g. in configuration property resolution through PropertyResourceConfigurer#setProperties(Properties)). If this is not desirable, use YamlMapFactoryBean instead.

The Properties created by this factory have nested paths for hierarchical objects, so for instance this YAML

 environments: dev: url: http://dev.bar.com name: Developer Setup prod: url: http://foo.bar.com name: My Cool App 
is transformed into these properties:
 environments.dev.url=http://dev.bar.com environments.dev.name=Developer Setup environments.prod.url=http://foo.bar.com environments.prod.name=My Cool App 
Lists are split as property keys with [] dereferencers, for example this YAML:
 servers: - dev.bar.com - foo.bar.com 
becomes properties like this:
 servers[0]=dev.bar.com servers[1]=foo.bar.com 

Functions

afterPropertiesSet

open fun afterPropertiesSet(): Unit

getObject

open fun getObject(): Properties

getObjectType

open fun getObjectType(): Class<*>

isSingleton

open fun isSingleton(): Boolean

setSingleton

open fun setSingleton(singleton: Boolean): Unit

Set if a singleton should be created, or a new object on each request otherwise. Default is true (a singleton).