0

I want to do something like:

@ConditionalOnProperty("${${appname}.someVal}")
@Controller
public class MyController {...}

Where my yaml would have:

appname: myapp
myapp:
  someVal: true

How would I do this?

EDIT: This does not work:

@Value("#{'${appname}.someVal'}")
Don Rhummy
  • 24,730
  • 42
  • 175
  • 330

1 Answers1

2

To evaluate SpEL, use @ConditionalOnExpression instead of @ConditionalOnProperty.

Does not look very elegant, but here it is:

@ConditionalOnExpression("#{environment.getProperty('${appname}.someVal') == 'true'}")

environment references a bean that implements org.springframework.core.env.Environment which is available in every Spring Boot application out of the box.

Maciej Walkowiak
  • 12,372
  • 59
  • 63