接口 PropertyResolver
- 所有已知子接口:
ConfigurableEnvironment
,ConfigurablePropertyResolver
,ConfigurableWebEnvironment
,Environment
- 所有已知实现类:
AbstractEnvironment
,AbstractPropertyResolver
,MockEnvironment
,PropertySourcesPropertyResolver
,StandardEnvironment
,StandardPortletEnvironment
,StandardServletEnvironment
public interface PropertyResolver
Interface for resolving properties against any underlying source.- 从以下版本开始:
- 3.1
- 作者:
- Chris Beams, Juergen Hoeller
- 另请参阅:
Environment
,PropertySourcesPropertyResolver
方法概要
所有方法 实例方法 抽象方法 已过时的方法 修饰符和类型 方法 说明 boolean
containsProperty(String key)
Return whether the given property key is available for resolution, i.e. if the value for the given key is notnull
.String
getProperty(String key)
Return the property value associated with the given key, ornull
if the key cannot be resolved.<T> T
getProperty(String key, Class<T> targetType)
Return the property value associated with the given key, ornull
if the key cannot be resolved.<T> T
getProperty(String key, Class<T> targetType, T defaultValue)
Return the property value associated with the given key, ordefaultValue
if the key cannot be resolved.String
getProperty(String key, String defaultValue)
Return the property value associated with the given key, ordefaultValue
if the key cannot be resolved.<T> Class<T>
getPropertyAsClass(String key, Class<T> targetType)
已过时。as of 4.3, in favor ofgetProperty(java.lang.String)
with manual conversion toClass
via the application'sClassLoader
String
getRequiredProperty(String key)
Return the property value associated with the given key (nevernull
).<T> T
getRequiredProperty(String key, Class<T> targetType)
Return the property value associated with the given key, converted to the given targetType (nevernull
).String
resolvePlaceholders(String text)
Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved bygetProperty(java.lang.String)
.String
resolveRequiredPlaceholders(String text)
Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved bygetProperty(java.lang.String)
.
方法详细资料
containsProperty
boolean containsProperty(String key)
Return whether the given property key is available for resolution, i.e. if the value for the given key is notnull
.
getProperty
String getProperty(String key)
Return the property value associated with the given key, ornull
if the key cannot be resolved.- 参数:
key
- the property name to resolve- 另请参阅:
getProperty(String, String)
,getProperty(String, Class)
,getRequiredProperty(String)
getProperty
String getProperty(String key, String defaultValue)
Return the property value associated with the given key, ordefaultValue
if the key cannot be resolved.- 参数:
key
- the property name to resolvedefaultValue
- the default value to return if no value is found- 另请参阅:
getRequiredProperty(String)
,getProperty(String, Class)
getProperty
<T> T getProperty(String key, Class<T> targetType)
Return the property value associated with the given key, ornull
if the key cannot be resolved.- 参数:
key
- the property name to resolvetargetType
- the expected type of the property value- 另请参阅:
getRequiredProperty(String, Class)
getProperty
<T> T getProperty(String key, Class<T> targetType, T defaultValue)
Return the property value associated with the given key, ordefaultValue
if the key cannot be resolved.- 参数:
key
- the property name to resolvetargetType
- the expected type of the property valuedefaultValue
- the default value to return if no value is found- 另请参阅:
getRequiredProperty(String, Class)
getPropertyAsClass
@Deprecated <T> Class<T> getPropertyAsClass(String key, Class<T> targetType)
已过时。as of 4.3, in favor ofgetProperty(java.lang.String)
with manual conversion toClass
via the application'sClassLoader
Convert the property value associated with the given key to aClass
of typeT
ornull
if the key cannot be resolved.- 抛出:
ConversionException
- if class specified by property value cannot be found or loaded or if targetType is not assignable from class specified by property value- 另请参阅:
getProperty(String, Class)
getRequiredProperty
String getRequiredProperty(String key) throws IllegalStateException
Return the property value associated with the given key (nevernull
).- 抛出:
IllegalStateException
- if the key cannot be resolved- 另请参阅:
getRequiredProperty(String, Class)
getRequiredProperty
<T> T getRequiredProperty(String key, Class<T> targetType) throws IllegalStateException
Return the property value associated with the given key, converted to the given targetType (nevernull
).- 抛出:
IllegalStateException
- if the given key cannot be resolved
resolvePlaceholders
String resolvePlaceholders(String text)
Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved bygetProperty(java.lang.String)
. Unresolvable placeholders with no default value are ignored and passed through unchanged.- 参数:
text
- the String to resolve- 返回:
- the resolved String (never
null
) - 抛出:
IllegalArgumentException
- if given text isnull
- 另请参阅:
resolveRequiredPlaceholders(java.lang.String)
,SystemPropertyUtils.resolvePlaceholders(String)
resolveRequiredPlaceholders
String resolveRequiredPlaceholders(String text) throws IllegalArgumentException
Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved bygetProperty(java.lang.String)
. Unresolvable placeholders with no default value will cause an IllegalArgumentException to be thrown.- 返回:
- the resolved String (never
null
) - 抛出:
IllegalArgumentException
- if given text isnull
or if any placeholders are unresolvable- 另请参阅:
SystemPropertyUtils.resolvePlaceholders(String, boolean)