Spring Boot - SpEL - Check List Contains - @ConditionalOnExpression

Viewed 1214

Given that I have the following properties:

values[0]=A
values[1]=B
values[2]=C

I need to check that values contains A in a @ConditionalOnExpression annotation. As of yet, I have not found an example of how to do it. I have tried this, but it does not work:

@ConditionalOnExpression("${values}.contains('A')")

It results in:

java.lang.IllegalStateException: Failed to load ApplicationContext
1 Answers

You need $ expresion surrounded by single quotes

@ConditionalOnExpression("'${values}'.contains('A')")
Related