Reputation: 2076
I have a Spring Boot application, with a class annotated as a @RestController
and also having @ConditionalOnProperty
annotation on my class MyRestController.kt
(kotlin) as below:
@RestController
@ConditionalOnProperty(value = ["app.running-mode.read-write"],havingValue = "true", matchIfMissing = true)
class MyRestController(private val r : MyRestService){
@GetMapping
// some endpoint here
@PostMapping
// some endpoint here
}
My application.properties
looks like this:
app.running-mode.read-write=${MY_API_RUNNING_MODE_READ_WRITE}
When I run my app sometimes, it crashes for a java.lang.IllegalStateException
on my class that contains this ConditionalOnProperty
annotation MyRestController.kt
, and I see it says:
Could not resolve placeholder 'MY_API_RUNNING_MODE_READ_WRITE` in value "${MY_API_RUNNING_MODE_READ_WRITE}"
This should be an environment variable set by Azure, but do I possibly have my @ConditionalOnProperty
defined incorrectly such that it is injecting the literal String, as seen in the logs, instead of the environment variable? (Which should be a boolean true
or false
, by the way)
Upvotes: 1
Views: 5103
Reputation: 6226
The issue could arise from how you have provided the value. Since you are injecting the value from environment for the different env, it's possible that the value may not be present or even provided wrongly in the environment. Check to veirfy that it's provided correctly. Make sure that the environment is configured with the key "MY_API_RUNNING_MODE_READ_WRITE".
Since you are reading the value from application.properties
then try providing it like below after removing '[]' :
@RestController
@ConditionalOnProperty(value = "app.running-mode.read-write",havingValue = "true", matchIfMissing = true)
class MyRestController(private val r : MyRestService){
@GetMapping
// some endpoint here
@PostMapping
// some endpoint here
}
Upvotes: 2