Overriding property settings in production
Everytime we take our application to a new environment, there are always settings that have to be adjusted. We don't want to edit code. Instead, it's easier if we could just override various properties. And we can!
This was touched on briefly in Chapter 10, Quick Start with Java, under the guise of overriding Spring Boot's property settings. However, the fact that we can write our own custom configuration property beans makes this a powerful feature for application customization.
To recap the rules listed in Chapter 10, Quick Start with Java, property settings can be overridden in the following order, highest to lowest:
@TestPropertySource
annotations on test classes.- Command-line arguments.
- Properties found inside
SPRING_APPLICATION_JSON
(inline JSON embedded in an env variable or system property). ServletConfig
init parameters.
ServletContext
init parameters.- JNDI attributes from
java:comp/env
. - Java System properties (
System.getProperties()
). - OS environment...