springboot study notes (eight)

1. The configuration file inside the project

1. The location of the configuration file

The configuration in properties and yml complement each other; if they conflict, properties have a higher priority.

Springboot can read two files application.properties/application.yml by default, and these two files can exist in the following 4 locations:

file: refers to a normal folder

classpath: refers to the internal path

①file: project root directory/config

②file: project root directory

③classpath: project root directory/config

④classpath: project root directory

note:

a. If there is a configuration conflict in the configuration files at different locations, the priority is ①>②>③>④

b. If there is no conflict, use complementary combination

2. Configure the project name

server.servlet.context-path=/Project name

2. Configuration files outside the project (suitable for when a large number of configurations need to be changed)

Benefit: Remedial project, no need to change the original project, only need to call external configuration file.

Example: For example, you need to change the port number 8882 to 8883,

Invoke the external configuration file via the command line:

java -jar project name.jar ----spring.config.location=file path

In the project Run configuration, arguments:

--spring.config.location=File path

If the same configuration exists in both the internal configuration file and the external configuration file, the external will overwrite the internal

3. Project operating parameters (suitable for when individual configuration needs to be changed)

Run configuration,arguments:

--server.port=Port number

Guess you like

Origin blog.csdn.net/dongjinkun/article/details/82957648