1. Configuration file
Springboot uses a global configuration file with a fixed configuration file name:
.application.properties
.application.yml
(You can choose one of the two above the configuration file)
The role of the configuration file: to modify the default value of Springboot's automatic configuration; Springboot is automatically configured for us at the bottom;
Syntax example of yml (YAML) file:
Syntax example of properties file:
2. Configuration file value injection (binding an attribute value in the configuration file to an entity class)
Use @ConfigurationProperties (prefix="property name") annotation to achieve
@ConfigurationProperties: Tell SpringBoot to bind all properties in this class to the relevant configuration in the configuration file;
prefix="attribute name": Which of the following attributes in the configuration file is mapped one by one
For example:
Configuration file:
javaBean:
(Note: Only if the bean component is a component in the container, can the @ConfigurationProperties function be provided to the container; that is to say, javaBean must be annotated with @ConfigurationProperties and must be annotated with @Component )
We can also import configuration file processors, and there will be prompts when writing configurations later