Developing Java Applications with Spring and Spring Boot
by Claudio Eduardo de Oliveira, Greg L. Turnquist, Alex Antonov
How it works...
Before delving into the details of an external configuration setup, let's quickly look at the code that was added in order to print the property value in the log. The element of focus is the @Value annotation that can be used on class fields or method arguments; it also instructs Spring to automatically inject the annotated variable with the value defined in the annotation. If the value is positioned in the wrapping curly braces prefixed with a dollar sign, (${ }), Spring will replace this with the value from the corresponding application property or with the default value, if it is provided, by adding the textual data after the colon (:).
In our case, we defined it as @Value("${my.config.value:}")String configValue, so unless ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access