类 PropertyOverrideConfigurer
- java.lang.Object
- org.springframework.core.io.support.PropertiesLoaderSupport
- org.springframework.beans.factory.config.PropertyResourceConfigurer
- org.springframework.beans.factory.config.PropertyOverrideConfigurer
- 所有已实现的接口:
BeanFactoryPostProcessor
,Ordered
,PriorityOrdered
public class PropertyOverrideConfigurer extends PropertyResourceConfigurer
Property resource configurer that overrides bean property values in an application context definition. It pushes values from a properties file into bean definitions.Configuration lines are expected to be of the following form:
beanName.property=value
Example properties file:dataSource.driverClassName=com.mysql.jdbc.Driver dataSource.url=jdbc:mysql:mydb
In contrast to PropertyPlaceholderConfigurer, the original definition can have default values or no values at all for such bean properties. If an overriding properties file does not have an entry for a certain bean property, the default context definition is used.Note that the context definition is not aware of being overridden; so this is not immediately obvious when looking at the XML definition file. Furthermore, note that specified override values are always literal values; they are not translated into bean references. This also applies when the original value in the XML bean definition specifies a bean reference.
In case of multiple PropertyOverrideConfigurers that define different values for the same bean property, the last one will win (due to the overriding mechanism).
Property values can be converted after reading them in, through overriding the
convertPropertyValue
method. For example, encrypted values can be detected and decrypted accordingly before processing them.- 从以下版本开始:
- 12.03.2003
- 作者:
- Juergen Hoeller, Rod Johnson
- 另请参阅:
PropertyResourceConfigurer.convertPropertyValue(java.lang.String)
,PropertyPlaceholderConfigurer
字段概要
字段 修饰符和类型 字段 说明 static String
DEFAULT_BEAN_NAME_SEPARATOR
The default bean name separator.从类继承的字段 org.springframework.core.io.support.PropertiesLoaderSupport
localOverride, localProperties, logger
从接口继承的字段 org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
构造器概要
构造器 构造器 说明 PropertyOverrideConfigurer()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected void
applyPropertyValue(ConfigurableListableBeanFactory factory, String beanName, String property, String value)
Apply the given property value to the corresponding bean.boolean
hasPropertyOverridesFor(String beanName)
Were there overrides for this bean?protected void
processKey(ConfigurableListableBeanFactory factory, String key, String value)
Process the given key as 'beanName.property' entry.protected void
processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
Apply the given Properties to the given BeanFactory.void
setBeanNameSeparator(String beanNameSeparator)
Set the separator to expect between bean name and property path.void
setIgnoreInvalidKeys(boolean ignoreInvalidKeys)
Set whether to ignore invalid keys.从类继承的方法 org.springframework.beans.factory.config.PropertyResourceConfigurer
convertProperties, convertProperty, convertPropertyValue, getOrder, postProcessBeanFactory, setOrder
从类继承的方法 org.springframework.core.io.support.PropertiesLoaderSupport
loadProperties, mergeProperties, setFileEncoding, setIgnoreResourceNotFound, setLocalOverride, setLocation, setLocations, setProperties, setPropertiesArray, setPropertiesPersister
字段详细资料
DEFAULT_BEAN_NAME_SEPARATOR
public static final String DEFAULT_BEAN_NAME_SEPARATOR
The default bean name separator.- 另请参阅:
- 常量字段值
构造器详细资料
PropertyOverrideConfigurer
public PropertyOverrideConfigurer()
方法详细资料
setBeanNameSeparator
public void setBeanNameSeparator(String beanNameSeparator)
Set the separator to expect between bean name and property path. Default is a dot (".").
setIgnoreInvalidKeys
public void setIgnoreInvalidKeys(boolean ignoreInvalidKeys)
Set whether to ignore invalid keys. Default is "false".If you ignore invalid keys, keys that do not follow the 'beanName.property' format (or refer to invalid bean names or properties) will just be logged at debug level. This allows one to have arbitrary other keys in a properties file.
processProperties
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) throws BeansException
从类复制的说明:PropertyResourceConfigurer
Apply the given Properties to the given BeanFactory.- 指定者:
processProperties
在类中PropertyResourceConfigurer
- 参数:
beanFactory
- the BeanFactory used by the application contextprops
- the Properties to apply- 抛出:
BeansException
- in case of errors
processKey
protected void processKey(ConfigurableListableBeanFactory factory, String key, String value) throws BeansException
Process the given key as 'beanName.property' entry.
applyPropertyValue
protected void applyPropertyValue(ConfigurableListableBeanFactory factory, String beanName, String property, String value)
Apply the given property value to the corresponding bean.
hasPropertyOverridesFor
public boolean hasPropertyOverridesFor(String beanName)
Were there overrides for this bean? Only valid after processing has occurred at least once.- 参数:
beanName
- name of the bean to query status for- 返回:
- whether there were property overrides for the named bean