Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot - SpEL - Check List Contains - @ConditionalOnExpression

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
like image 643
GreenSaguaro Avatar asked Sep 19 '25 05:09

GreenSaguaro


1 Answers

You need $ expresion surrounded by single quotes

@ConditionalOnExpression("'${values}'.contains('A')")
like image 79
Deadpool Avatar answered Sep 21 '25 04:09

Deadpool