实践Spring Boot之Web容器

Spring boot默认内嵌tomcat作为Servlet容器,也支持Jetty和Undertow等。

通用配置

配置类:org.springframework.boot.autoconfigure.web.ServerProperties,配置前缀:server,例如:

1
2
# 默认8080
server.port=80

Session配置

tomcat配置

配置类:org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat,配置前置:server.tomcat,例如:

1
2
3
4
# 默认UTF-8
server.tomcat.uri-encoding=
# 默认off
server.tomcat.compression

Jetty配置

替换为jetty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
	<exclusions>
		<exclusion>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

配置类:org.springframework.boot.autoconfigure.web.ServerProperties.Jetty,配置前置:server.jetty,例如:

1
server.jetty.acceptors=

自定义

org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer

org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory