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