举个例子:
@ConditionalOnProperty(value = "spring.mvc.favicon.enabled",
matchIfMissing = true)
- 当配置文件中没有spring.mvc.favicon.enabled时,由于matchIfMissing = true,属于条件匹配。
- 当配置文件中有spring.mvc.favicon.enabled时,此时配合havingValue,如下表。havingValue默认为“”,spring.mvc.favicon.enabled=true时属于条件匹配(yes), spring.mvc.favicon.enabled=false时属于条件不匹配(no)
| Property Value | havingValue="" | havingValue="true" | havingValue="false" | havingValue="foo" |
|---|---|---|---|---|
| "true" | yes | yes | no | no |
| "false" | no | no | yes | no |
| "foo" | yes | no | no | yes |