Springboot YML Configuration

Source: Internet
Author: User

1. In spring boot, there are two kinds of configuration files, one is application.properties and the other is application.yml, both of which can be configured to define some variables in the Spring boot project, set parameters, and so on. Here's the difference between the two.

Application.properties configuration files should be written in full, such as:

Spring.profiles.active=dev
Spring.datasource.data-username=root
Spring.datasource.data-password=root

To configure in the Yml file, the following is the wording:

  

Spring
Profiles
Active:prod
DataSource
Driver-class-name:com.mysql.jdbc.driver
Url:jdbc:mysql://127.0.0.1:3306/test
Username:root
Password:root

The Yml file has a strong level of writing and writes less code. So now a lot of people are using the YML configuration file.

2. Configure the configuration method for multiple sets of environments in the project.
Because now a project has a lot of environment, development environment, test environment, quasi-production environment, production environment, the parameters of each environment, so we can configure the parameters of each environment to the Yml file, so that when you want to use the environment only in the main configuration file will be used in the configuration file to write the following:

Spring
Profiles

This line is configured in the Application.yml file, meaning that the currently functioning profile is APPLICATION_PROD.YML, and the other configuration files are named Application_dev.yml,application_bat.yml.

3. Java-jar Xxxxxx.jar can also be set when the project is started Spring.profiles.actiove=prod it is also possible to start the setup configuration file, but this is only for development and testing.

4. Read the profile data:
Massage:
Data
Name:qibaoyi
I want to get in the class he needs to write like this:
@Value ("${message.data.name}")
private String name;

The value that you take to the variable name is the value configured in the configuration file.

5. It is important to note that the parameters in the configuration file are written as follows: There is a space in the middle of the name:qibaoyi, and it will alert you in the idea compiler.




















Springboot YML Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.