Issue
I have some code to load a value as such in my Spring application:
@Component
public class MyElasticRestService {
@Value("${elasticApi.baseURL}")
private String elasticApiBaseUrl;
According to href="https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-relaxed-binding" rel="noreferrer">the Spring docs, I should be able to use a relaxed binding that comes from an uppercase environment variable such as ELASTIC_API_BASE_URL
or ELASTICAPI_BASEURL
. But I'm confused which is correct. Both don't seem to work so I am wondering how to debug what is actually picked up.
I've loaded Spring Boot Actuator to view the configprops
endpoint. But it doesn't have anything on the elasticApi
prefix.
What should the correct environment variable be and how can I see how it gets translated and picked up by the application?
Solution
The @Value
annotation doesn't support relaxed bindings. Therefore you could use a class annotated with @ConfigurationProperties
or you use a RelaxedPropertyResolver
to get the value from the environment.
Answered By - joshiste
Answer Checked By - Timothy Miller (JavaFixing Admin)