We're implementing Spring Boot application (v2.2.5) and there is a configuration that use @Value annotation as below (org.springframework.beans.factory.annotation.Value
).
@Value("${something.about:abcd}")
private String somethingAbout;
In the application.yml
file, we have property like this.
something:
about: real_value
In this @Value annotation, I intended to work that as below:
- Use the property value when it's defined in the application.yml file.
- Otherwise, use the default value(abcd)
However, it does not read and set the existing property value to the variable. The variable is set as "abcd".
@Value("${something.about}") // Works fine
@Value("${something.about:abcd}") // It uses 'abcd' even the property exist
Is there anything that I missed?