1. How to set the value
First, we enter ServerProperties to check its content: we
find that there is an annotation
@ConfigurationProperties(
prefix = "server",
ignoreUnknownFields = true
)
prefix as the prefix, and the prefix is named server, so we can use server in properties, yaml, and yml files. Attribute configuration is performed in xxx mode. We click into the spring-boot-starter-parent in the pom.xml file:
Springboot will go to the resources path to load the file that meets the requirements, and find the configuration from the file to overwrite the default configuration. The file requirements are as follows:
if multiple files are set with the same configuration, the last file will overwrite the configuration of the previous file. For example, yaml will cover yml, and properties will cover yaml, that is to say:
properties> yaml> yml
2. Why is the default value 8080
The dependencies we import are all jar packages. The default configuration information is stored in the jar package whose package name ends in *-autoconfigure.jar. The name of the springboot default configuration file is: /META-INF/spring-configuration-metadata.json .
/META-INF/additional-spring-configuration-metadata.json, this file is also the default configuration, which is the supplementary configuration information in the /META-INF/spring-configuration-metadata.json file:
click into spring-configuration-metadata. In json, check its content and find that the default value of server.port has been configured in it, and the default value is 8080: