问题
I am trying to condtionally create a component using @ConditionalOnExpression("not ${service.synchronous} && not ${service.disabled}")
.
I based this on Spring Boot SpEL ConditionalOnExpression check multiple properties, which provides a multi-property conditional as follows: @ConditionalOnExpression("${properties.first.property.enable:true} && ${properties.second.property.startServer:false}")
However, I keep getting:
Caused by: org.springframework.expression.spel.SpelParseException: EL1041E: After parsing a valid expression, there is still more data in the expression: 'lcurly({)'
Those properties are always set in my .properties file so I did not provide a default value with the colon notation. What am I doing wrong?
回答1:
In most such cases the properties your app is reading are not what you expect them to be.
Set a breakpoint on all constructors of SpelParseException. In the debugger you will see the expression that is parsed, that will give show you exactly which properties you are really using.
Maybe you have to go search a little in the stack until you find the right location where you can see the expression.
回答2:
You will need to provide the default values for your properties like in the example you followed, so update the expression to be:
@ConditionalOnExpression("not ${service.synchronous:false} && not ${service.disabled:true}")
来源:https://stackoverflow.com/questions/49714249/spelparseexception-after-parsing-a-valid-expression-there-is-still-more-data-i