spring boot 默认采用tomcat作为嵌入的web容器
定制方式有三种
1. 2.如下
@Component
public class CustomizationBean implements EmbeddedServletContainerCustomizer{ /**
* 定制方法一:实现EmbeddedServletContainerCustomizer
* @param container
*/
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
//container.setPort(9000);
} /**
* 定制方法二:注入EmbeddedServletContainerFactory
* @return
*/
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
factory.setPort(9001);
factory.setSessionTimeout(10, TimeUnit.MINUTES);
//优先级高于配置在/static/error文件夹里面的404.html页面
factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/error/403.html"));
return factory;
}
}
3.配置文件添加相关配置,如下
#=====================servlet container config==================
server.port=8080
server.ssl.enabled=false
server.address=127.0.0.1
server.session.persistent=true
#1800 seconds,30 minutes
server.session.timeout=1800
server.session.store-dir=/Users/hdwang/sessiontmp