我正在尝试使用创建一个组件@ConditionalOnExpression("not ${service.synchronous} && not ${service.disabled}")。
我基于Spring Boot SpEL ConditionalOnExpression检查多个属性,它提供了如下的多属性条件:@ConditionalOnExpression("${properties.first.property.enable:true} && ${properties.second.property.startServer:false}")
但是,我不断得到:
Caused by: org.springframework.expression.spel.SpelParseException: EL1041E: After parsing a valid expression, there is still more data in the expression: 'lcurly({)'
这些属性始终在我的.properties文件中设置,因此我没有提供带有冒号的默认值。我究竟做错了什么?
您将需要为您的属性提供默认值,如您所遵循的示例中所示,因此将表达式更新为:
@ConditionalOnExpression("not ${service.synchronous:false} && not ${service.disabled:true}")
Run Code Online (Sandbox Code Playgroud)
在大多数此类情况下,您的应用程序正在读取的属性并不是您所期望的。
在 SpelParseException 的所有构造函数上设置断点。在调试器中,您将看到已解析的表达式,它将准确显示您真正使用的属性。
也许您必须在堆栈中进行一些搜索,直到找到可以看到表达式的正确位置。
| 归档时间: |
|
| 查看次数: |
1958 次 |
| 最近记录: |