Java boot project configuration method priority

The java boot project understands the configuration files
in three formats. The three configuration file formats supported in the boot project we mentioned are
application.properties
application.yml
application.yaml

Among them, we also recommend that everyone use the application.yml format.
Then the question arises. If all three files exist in the resources directory, who will the system listen to?

It's very simple. We build all three files under resources
insert image description here
. application.properties set port number 80
insert image description here
application.yml set port number 81
insert image description here
application.yaml set port number 82
insert image description here
let's start it to see who is dominant

After starting, we look at the output information.
insert image description here
The starting port is 80.
It is obvious that the system uses application.properties

So the boss is application.properties,
let's kill application.properties now,
insert image description here
the boss has been confirmed, let's see who is the second child now?
Run the project again,
insert image description here
the startup port is 81, obviously the second one is application.yml

So let’s talk about all the configurations will take effect,
but if you have the same configuration, such as ports, etc., it will be loaded according to the priority. The
priority is
application.properties, the highest
application.yml, and the second
application.yaml is the lowest .

Guess you like

Origin blog.csdn.net/weixin_45966674/article/details/130876005