官术网_书友最值得收藏!

Order of evaluation for overridden properties

Let's see the following order of evaluation for overridden properties:

  1. Defined properties for the Devtools global settings in your home directory
  2. Defined properties for @TestPropertySource annotations on your tests
  3. Properties as command-line arguments
  4. Defined properties from SPRING_APPLICATION_JSON
  5. The properties with ServletConfig init parameters
  6. The properties with ServletContext init parameters
  7. JNDI attributes from java:comp/env
  8. Java system properties
  9. OS environment variables
  10. Property file(s)—including application.properties and its YAML variant

This preceding list is in order of precedence. That means if you set any property from a source higher in the list, Spring will override the same property defined in the source lower in the list. The test environment and command-line arguments override properties from any other property source.

Let's see the following order of evolution of the properties file and YAML variants:

  1. A RandomValuePropertySource class that injects properties with random value into configuration file define as random.*
  2. Profile-specific application properties outside of your packaged JAR, that is, in the /config subdirectory of the directory from which the application is run (application-{profile}.properties and YAML variants)

Select a profile by executing the JAR with param Dspring.profiles.active=dev or setting the property spring.profiles.active=dev.

  1. Profile-specific application properties outside of your packaged JAR but in a directory from which the application is run (application-{profile}.properties and YAML variants)
  2. Profile-specific application properties packaged inside your JAR but in a package named config (application-{profile}.properties and YAML variants)
  3. Profile-specific application properties packaged inside your JAR but at the root of the classpath (application-{profile}.properties and YAML variants)
  4. Application properties outside of your packaged JAR, that is, in the /config subdirectory of the directory from which the application is run (application.properties and YAML variants)
  5. Application properties outside of your packaged JAR but in a directory from which the application is run (application.properties and YAML variants)
  1. Application properties packaged inside your JAR but in a package named config (application.properties and YAML variants)
  2. Application properties packaged inside your JAR but at the root of the classpath (application.properties and YAML variants)
  3. @PropertySource annotations on your @Configuration classes
  4. Default properties (specified using SpringApplication.setDefaultProperties)

According to the order of precedence, if you set any properties in a profile-specific application-{profile}.properties will override the same properties set in an application.properties file at the same location as the application-{profile}.properties file.

Again, this list is in order of precedence. That is, an application.properties file in a /config subdirectory will override the same properties set in a application.properties file in the application's classpath.

Let's see how to customize the name of the application property file (application.properties).

主站蜘蛛池模板: 昌黎县| 阜康市| 积石山| 淳安县| 堆龙德庆县| 于都县| 双辽市| 石柱| 丹巴县| 泸西县| 泌阳县| 邯郸市| 绥宁县| 高雄市| 长沙县| 靖远县| 南宁市| 湾仔区| 桐乡市| 澎湖县| 肇州县| 英山县| 栾城县| 阿鲁科尔沁旗| 潼关县| 乐东| 子洲县| 秦安县| 封开县| 连平县| 靖江市| 那坡县| 南充市| 湖南省| 罗平县| 永川市| 台州市| 锡林郭勒盟| 蒲城县| 大田县| 新乐市|