The content of this article is about the method (code example) of using the application.yml configuration file in Spring Boot. It has certain reference value and friends in need can refer to it. I hope it helps you.
The configuration file generated by Spring Boot by default is application.properties. In fact, there is not much difference between application.yml and application.properties.
It’s just that the hierarchical structure is obvious and more readable, so it is currently used more.
We assume that the original configuration of application.properties is:
server.port=8082
So how to switch the configuration file to application.yml?
First delete the original default configuration file application.properties and add a new configuration file application.yml as follows:
##Modify application.yml to:
server: port: 8082
Note: There is a space between the : after port and 8082, it cannot be omitted
If you are not careful Omitting the spaces, in fact, IDEA can also see it, but it does not display errors and does not affect startup.
We now modify the configuration file to be wrong (omit the spaces), and then Start the project
##We will find that although the project starts successfully, the configuration Port number 8082 has not taken effect, and the default port number 8080 is still started.
Regarding the problem of configuring multiple environments in application.yml, please refer to the blog I wrote before. Spring Boot uses Profile to implement multi-environment configuration. manage
The above is the detailed content of How Spring Boot uses the application.yml configuration file (code example). For more information, please follow other related articles on the PHP Chinese website!