Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpelParseException: After parsing a valid expression, there is still more data in the expression: 'lcurly({)'

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?

like image 513
Phillip Godzin Avatar asked Apr 08 '18 03:04

Phillip Godzin


3 Answers

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}")
like image 62
Wil Avatar answered Oct 26 '22 10:10

Wil


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.

like image 43
Stefan Isele - prefabware.com Avatar answered Oct 26 '22 10:10

Stefan Isele - prefabware.com


My mistake was that I had not imported the test properties file in a Spring test. After I added @TestPropertySource("classpath:/application.properties") to the test class, the properties from the properties file were used.

like image 1
havryliuk Avatar answered Oct 26 '22 08:10

havryliuk