SpringBoot-- loading position and the external profile configuration profile load loading order SpringBoot priority position

statement

Section of this article switched: SpringBoot profile load position priority

text

1. Project internal configuration file

spring boot started, it scans the following locations application.properties or application.yml Spring boot file as the default profile

  –file:./config/
  –file:./
  –classpath:/config/
  –classpath:/


These are in descending order of priority, all the files are loaded position, the high priority of the contents will be overwritten low priority configuration content.

SpringBoot will be loaded from the four positions of all main configuration file, if the file attributes and attribute the low priority profile does not conflict a high priority in the configuration, it will co-exist - complementary configuration.


We can also change the default configuration by configuring spring.config.location.

the Spring-the Boot--jar the Java 02-config-02-0.0.1-SNAPSHOT.jar --spring.config.location = File: /// D: /application.properties,classpath: /, the CLASSPATH: / config /
project after a good package, we can use the command-line parameters in the form of, when the project started to specify the new location of the configuration file.

Specify the configuration file and the default load of these configuration files work together to form a complementary configuration.
Idea single probe enable custom configuration: Add jvm parameters: -Dspring.config.location = file: /// D: /project_conf/application.yml -ea


 

2. External Configuration loading sequence

SpringBoot position may also be loaded from the following configurations: low priority level; high priority is configured to cover a low priority configuration, and any configuration may complement the configuration.

1. command-line arguments

  • All configurations can be specified on the command line;
  • A plurality of configuration separated by spaces; - = CI value

  java -jar spring-boot-02-config-02-0.0.1-SNAPSHOT.jar --server.port=8087 --server.context-path=/abc

2. from java: comp / env JNDI properties of 

3.Java system properties (System.getProperties ()) 

4. The operating system environment variables 

random 5.RandomValuePropertySource configuration. * Property Value

6.jar external package or application- {profile} .properties application.yml (with spring.profile) profile

7.jar inner package or application- {profile} .properties application.yml (with spring.profile) profile

8.jar application.properties outside the package or application.yml (without spring.profile) profile

Application.properties package or inside 9.jar application.yml (without spring.profile) profile

@PropertySource 10. @ Configuration annotation on the class 

11. By default attributes specified SpringApplication.setDefaultProperties

Refer to the official website address

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/yadongliang/p/11695936.html