Why is the default value of server.port in SpringBoot 8080 and how to modify the port number

1. How to set the value

First, we enter ServerProperties to check its content: we
Insert picture description here
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:
Insert picture description here

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:
Insert picture description here
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:
Insert picture description here
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:
Insert picture description here

Guess you like

Origin blog.csdn.net/MrYushiwen/article/details/112103559