1.Spring Boot中内嵌了Tomcat、Jetty和Undertow服务器。
默认情况下,内嵌的服务器HTTP请求监听8080端口。
2.Spring Boot默认servlet容器为tomcat。
一、配置Tomcat
1.配置端口号
Spring Boot 默认端口是8080,如果想要进行更改的话,在配置文件中
加入:
server.port=8081
2.配置context-path
server.servlet.context-path=/spring-boot
访问地址:
http://ip:port/spring-boot
3.配置session的超时时间
server.servlet.session.timeout=2M
二、替换Tomcat
如果要使用Jetty或者Undertow为Servlet容器,只需修改spring-boot-starter-web依赖
2.使用Jetty servlet容器
在pom.xml中,将spring-boot-starter-web的依赖由spring-boot-start
er-tomcat替换为spring-boot-starter-jetty
<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>
2.使用Undertow servlet容器
在pom.xml中,将spring-boot-starter-web的依赖由spring-boot-start
er-tomcat替换为spring-boot-starter-undertow
<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-undertow</artifactId>
</dependency>
此时需要将tomcat-embed-jasper注释掉
<!-- <dependency>-->
<!-- <groupId>org.apache.tomcat.embed</groupId>-->
<!-- <artifactId>tomcat-embed-jasper</artifactId>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->