【问题标题】:SpelParseException: After parsing a valid expression, there is still more data in the expression: 'lcurly({)'SpelParseException:解析有效表达式后,表达式中还有更多数据:'lcurly({)'
【发布时间】:2018-04-08 03:51:43
【问题描述】:

我正在尝试使用@ConditionalOnExpression("not ${service.synchronous} && not ${service.disabled}") 有条件地创建一个组件。

我基于Spring Boot SpEL ConditionalOnExpression check multiple properties,它提供了一个多属性条件如下:@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 文件中设置,所以我没有使用冒号表示法提供默认值。我做错了什么?

【问题讨论】:

    标签: spring spring-el


    【解决方案1】:

    您将需要为您的属性提供默认值,就像您遵循的示例一样,因此将表达式更新为:

    @ConditionalOnExpression("not ${service.synchronous:false} && not ${service.disabled:true}")
    

    【讨论】:

      【解决方案2】:

      在大多数此类情况下,您的应用正在读取的属性并不是您所期望的。

      在 SpelParseException 的所有构造函数上设置断点。在调试器中,您将看到已解析的表达式,它将准确显示您真正使用的属性。

      也许您必须在堆栈中搜索一下,直到找到可以看到表达式的正确位置。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-11-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-20
        • 1970-01-01
        • 1970-01-01
        • 2011-12-12
        相关资源
        最近更新 更多