1.Spring Boot中内嵌了Tomcat、Jetty和Undertow伺服器。
預設情況下,内嵌的伺服器HTTP請求監聽8080端口。
2.Spring Boot預設servlet容器為tomcat。
一、配置Tomcat
1.配置端口号
Spring Boot 預設端口是8080,如果想要進行更改的話,在配置檔案中
加入:
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>-->