版权声明:看什么?6,你和我,走一波! https://blog.csdn.net/qq_31323797/article/details/84833397
- 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 {
//配置嵌入式的Servlet容器
@Bean
public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
/*return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
// 定制Servlet容器的相关规则
@Override
public void customize(ConfigurableWebServerFactory factory) {
factory.setPort(8081);
}
};*/
// 该段代码为上面代码的lambda的表达
return factory -> factory.setPort(8081);
}
}