注释类型 ConditionalOnProperty
@Retention(RUNTIME) @Target({TYPE,METHOD}) @Documented @Conditional(org.springframework.boot.autoconfigure.condition.OnPropertyCondition.class) public @interface ConditionalOnProperty
Conditional
that checks if the specified properties have a specific value. By default the properties must be present in theEnvironment
and not equal tofalse
. ThehavingValue()
andmatchIfMissing()
attributes allow further customizations.The
havingValue()
attribute can be used to specify the value that the property should have. The table below shows when a condition matches according to the property value and thehavingValue()
attribute:Property Value havingValue=""
havingValue="true"
havingValue="false"
havingValue="foo"
"true"
yes yes no no "false"
no no yes no "foo"
yes no no yes If the property is not contained in the
Environment
at all, thematchIfMissing()
attribute is consulted. By default missing attributes do not match.- 从以下版本开始:
- 1.1.0
可选元素概要
可选元素 修饰符和类型 可选元素 说明 String
havingValue
The string representation of the expected value for the properties.boolean
matchIfMissing
Specify if the condition should match if the property is not set.String[]
name
The name of the properties to test.String
prefix
A prefix that should be applied to each property.boolean
relaxedNames
If relaxed names should be checked.String[]
value
Alias forname()
.
name
String[] name
The name of the properties to test. If a prefix has been defined, it is applied to compute the full key of each property. For instance if the prefix isapp.config
and one value ismy-value
, the fully key would beapp.config.my-value
Use the dashed notation to specify each property, that is all lower case with a "-" to separate words (e.g.
my-long-property
).- 返回:
- the names
- 默认值:
- {}
havingValue
String havingValue
The string representation of the expected value for the properties. If not specified, the property must not be equals tofalse
.- 返回:
- the expected value
- 默认值:
- ""
matchIfMissing
boolean matchIfMissing
Specify if the condition should match if the property is not set. Defaults tofalse
.- 返回:
- if should match if the property is missing
- 默认值:
- false
relaxedNames
boolean relaxedNames
If relaxed names should be checked. Defaults totrue
.- 返回:
- if relaxed names are used
- 默认值:
- true