Spring boot configuration file default placement, and load priority

First, the default configuration file directory

  spring boot will start scanning the application.properties or application.yml file location as a spring boot default configuration file, loaded from top to bottom priority, load time, will the Road King of the files are loaded again. All the contents of a different configuration will be loaded into the system, to duplicate the configuration of the content, priority high profile content will cover priority low profile content.

 
Road King Explanation
file:./config/ Project folder config directory under.
file:/ Project folder directory, and then if the project is a maven pom.xml is a hierarchy
classPath:/config/ config file folder under the project folder classPath
classPath:/ Project classpath folder

  In addition to the file directory, it can also be used spring.config.location formal parameter configuration file specifies: Java -jar Boot-02-Spring-config-02-0.0.1-SNAPSHOT.jar --spring.config.location = G: /application.properties, if the above Road King default profile, then there will be formed and arranged complementarity contents, the contents of the same high priority override lower priority.


Second, the external arrangement

  Sometimes the project has been labeled jar, and want to change the system configuration, SpringBoot can also set parameters from the jar out of the package, load configuration; the following settings highest to lowest priority; high-priority configuration override low priority configuration, all complementary configurations arranged form

  1. command line parameters
    ; all of the configurations can be specified on the command line, separated by spaces arranged plurality  - CI = value
    java -jar spring-boot-02- config-02-0.0 8087-SNAPSHOT.jar --server.port = .1 --server.context-path = / ABC
  2. from java: comp / env in JNDI properties
  3.Java system properties ( System.getProperties () )
  4. operating system environment variables
  5.RandomValuePropertySource configuration . random * property values
  creating the configuration file in the directory hierarchy engineering jar package, such as:  so start your project as a parameter:
java -jar spring-boot-02- config-02-0.0.1-SNAPSHOT.jar, load the configuration file, according to the following rules,   the jar package outgoing jar were looking for the bag;

  Priority load belt Profile
  6.jar outside the package application- {profile} .properties or application.yml ( with spring.profile) profile
  7.jar inside a package application- {profile} .properties or application.yml ( with spring. profile) profile
  again without loading profile
  8.jar external packet application.properties or application.yml ( without spring.profile) profile
  9.jar within the package application.properties or application.yml ( without spring.profile ) profile
  10. @ configuration on annotation class@PropertySource
  11. By SpringApplication.setDefaultProperties specified default properties
  for all supported configurations load source;

 

Guess you like

Origin www.cnblogs.com/jonrain0625/p/11462672.html