spring-boot 替换内嵌tomcat版本
spring-boot中的内嵌tomcat有默认的指定版本,若想修改为其他版本,有以下两种途径:
使用parent的方式
若引入spring-boot的方式为加入<parent>:
1<!-- Inherit defaults from Spring Boot -->
2<parent>
3 <groupId>org.springframework.boot</groupId>
4 <artifactId>spring-boot-starter-parent</artifactId>
5 <version>1.3.0.BUILD-SNAPSHOT</version>
6</parent>
则只需在properties中指定tomcat版本即可:
1<properties>
2 <tomcat.version>7.0.59</tomcat.version>
3</properties>
这种方式比较简单,官方文档中也有说明
使用dependencyManagement的方式
有时我们的项目中有自己的parent,则需要使用<dependencyManagement>的方式引入spring-boot:
1<properties>
2 <tomcat.version>7.0.59</tomcat.version>
3</properties>
4...
5<dependencyManagement>
6 <dependencies>
7 <dependency>
8 <!-- Import dependency management from Spring Boot -->
9 <groupId>org.springframework.boot</groupId>
10 <artifactId>spring-boot-dependencies</artifactId>
11 <version>1.3.0.BUILD-SNAPSHOT</version>
12 <type>pom</type>
13 <scope>import</scope>
14 </dependency>
15 </dependencies>
16</dependencyManagement>
此时修改内嵌tomcat的版本则需要在<dependencyManagement>中加入内嵌tomcat的所有依赖,以替换默认的tomcat:
1<dependencyManagement>
2 <dependencies>
3 <!-- 替换spring-boot内嵌tomcat -->
4 <dependency>
5 <groupId>org.apache.tomcat.embed</groupId>
6 <artifactId>tomcat-embed-core</artifactId>
7 <version>${tomcat.version}</version>
8 </dependency>
9 <dependency>
10 <groupId>org.apache.tomcat.embed</groupId>
11 <artifactId>tomcat-embed-el</artifactId>
12 <version>${tomcat.version}</version>
13 </dependency>
14 <dependency>
15 <groupId>org.apache.tomcat.embed</groupId>
16 <artifactId>tomcat-embed-logging-juli</artifactId>
17 <version>${tomcat.version}</version>
18 </dependency>
19 <dependency>
20 <groupId>org.apache.tomcat.embed</groupId>
21 <artifactId>tomcat-embed-jasper</artifactId>
22 <version>${tomcat.version}</version>
23 </dependency>
24 <dependency>
25 <groupId>org.apache.tomcat.embed</groupId>
26 <artifactId>tomcat-embed-websocket</artifactId>
27 <version>${tomcat.version}</version>
28 </dependency>
29 <dependency>
30 <groupId>org.apache.tomcat</groupId>
31 <artifactId>tomcat-jdbc</artifactId>
32 <version>${tomcat.version}</version>
33 </dependency>
34 <dependency>
35 <groupId>org.apache.tomcat</groupId>
36 <artifactId>tomcat-jsp-api</artifactId>
37 <version>${tomcat.version}</version>
38 </dependency>
39 </dependencies>
40</dependencyManagement>
这种方式比较麻烦,但在不能引入parent和需要修改tomcat版本的情况下,也是无赖之举。
-END-
