Home > Java > javaTutorial > body text

How Spring Boot uses the application.yml configuration file (code example)

不言
Release: 2019-01-18 09:46:19
forward
9165 people have browsed it

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
Copy after login

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
Copy after login

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!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!