- SpringBoot默认使用Tomcat作为嵌入式的Servlet容器
1 自定义Server相关配置
1.1 通过application.properties自定义
# 通用的Servlet容器设置
server.port=8081
# Tomcat的设置--server.tomcat.xxx
server.tomcat.uri-encoding=UTF-8
1.1.1 属性来源
org.springframework.boot.autoconfigure.web.ServerProperties
1.2 通过WebServerFactoryCustomizer自定义
package com.gp6.springboot19.config;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MyConfig {
@Bean
public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
return factory -> factory.setPort(8081);
}
}
1.2.1 测试结果