如何从 Spring 集成配置文件中的环境变量创建布尔值?

How to create boolean value from an environmental variable in Spring Integration configuration file?

基于我有基于环境变量sd的自动启动条件:

<int:chain auto-startup="#{environment.getProperty('sd', true)}">

根据上述规范,sd 可以为 true 或 false,否则条件无效。如果我只想在 sd 等于例如“connect”时启动怎么办?

auto-startup 无论如何都是背景上的 boolean 选项,因此您别无选择,除非 return booleantrue/false 来自该 SpEL 的字符串。 顺便说一句,10onoff 也很好用 - StringToBooleanConverter.

所以,你应该稍微提高你的 SpEL:

<int:chain auto-startup="#{environment.getProperty('sd', 'connect') == 'connect'}">