https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.htmlhtml
Spring Boot lets you externalize your configuration so that you can work with the same application code in different environments. You can use properties files, YAML files, environment variables, and command-line arguments to externalize configuration. Property values can be injected directly into your beans by using the @Value
annotation, accessed through Spring’s Environment
abstraction, or be bound to structured objects through @ConfigurationProperties
.java
Spring Boot uses a very particular PropertySource
order that is designed to allow sensible overriding of values. Properties are considered in the following order:spring
~/.spring-boot-devtools.properties
when devtools is active).@TestPropertySource
annotations on your tests.properties
attribute on your tests. Available on @SpringBootTest
and the test annotations for testing a particular slice of your application.SPRING_APPLICATION_JSON
(inline JSON embedded in an environment variable or system property).ServletConfig
init parameters.ServletContext
init parameters.java:comp/env
.System.getProperties()
).RandomValuePropertySource
that has properties only in random.*
.application-{profile}.properties
and YAML variants).application-{profile}.properties
and YAML variants).application.properties
and YAML variants).application.properties
and YAML variants).@PropertySource
annotations on your @Configuration
classes.SpringApplication.setDefaultProperties
).