Spring Boot默认内嵌的Tomcat为Servlet容器,关于Tomcat的所有属性都在ServerProperties配置类中。同时,也可以实现一些接口来自定义内嵌Servlet容器和内嵌Tomcat等的配置。
关于此配置,网络上有大量的资料,但都是基于SpringBoot1.5.x版本,并不适合当前最新版本。本文将带大家了解一下最新版本的使用。
ServerProperties的部分源码:
@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
public class ServerProperties {
private Integer port;
// ...
public static class Servlet {
private String contextPath;
// ...
}
public static class Tomcat {
private int maxThreads = 200;
private int minSpareThreads = 10;
// ...
}
}
通过源码可以看出Servlet容器配置都以"server"作为前缀,而Tomcat相关配置都以"server.tomcat"作为前缀。
application.properties配置
通常只需在application.properties配置文件中针对具体的属性进行配置即可。
常见的servlet容器配置如下:
server.port = #配置程序端口,默认为8080
server.session-timeout=#用户session过期,以秒为单位
server.context-path= #配置访问路径,默认为/
常见的Tomcat配置如下:
server