1、如果是gradle工程,有两种方式;
方式一、在全局配置中修改;
添加exclude
exclude module:'spring-boot-starter-tomcat'
方式二、在compile排除:
compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
最后添加undertow依赖:
compile 'org.springframework.boot:spring-boot-starter-undertow:2.7.0'
2、如果是maven工程:
直接排除后添加依赖既可;
<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>
3、如果只是替换tomcat版本:
先排除内置版本,然后添加指定tomcat版本
compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compile 'org.apache.tomcat.embed:tomcat-embed-core:8.5.51'
compile 'org.apache.tomcat.embed:tomcat-embed-el:8.5.51'
compile 'org.apache.tomcat.embed:tomcat-embed-websocket:8.5.51'
maven项目只需要修改pom.xml文件
添加tomcat指定版本
<tomcat.version>9.0.58</tomcat.version>