简言
SpringBoot内置的tomcat版本是随着SpringBoot版本走的,比如我这SpringBoot 版本是1.5.9,内置tomcat版本是8.5.23;假如需要修改内置的tomcat版本号,则在POM依赖里< properties >里添加< tomcat.version>8.0.42< /tomcat.version>
注意:我上面标签是有空格的;
<properties>
<tomcat.version>8.0.42</tomcat.version>
</properties>
指定完tomcat版本后可以查看maven 依赖树,查看内置tomcat版本是否变为指定版本,重启项目,但是有时候启动会报错:
Tomcat启动报错代码 :
Caused by: java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
at org.apache.catalina.util.LifecycleBase.<clinit>(LifecycleBase.java:37)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:169)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134)
... 13 common frames omitted
因为这个时候的tocmat缺少jar包,maven项目的话加上下面这个依赖就好了:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-juli</artifactId>
<version>${tomcat.version}</version>
</dependency>
修改完后,能在控制台启动日志里看到tomcat的启动版本:
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _
( ( )___ | ‘_ | ‘
| | ’
/
` |
/
)| |
)| | | | | || (
| | ) ) ) )
’ |
| .__|
| |
|
| |
, | / / / /
=========|
|==============|
/=/
/
/_/
:: Spring Boot :: (v1.5.9.RELEASE)
2018-03-09 11:01:58.104 INFO 5036 --- [ main] com.jd.m.tg.MTgApplication : The following profiles are active: dev
2018-03-09 11:01:58.218 INFO 5036 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@9bfddc: startup date [Fri Mar 09 11:01:58 CST 2018]; root of context hierarchy
2018-03-09 11:01:58.546 INFO 5036 --- [kground-preinit] o.h.validator.internal.util.Version : HV000001: Hibernate Validator 5.3.6.Final
2018-03-09 11:02:01.176 INFO 5036 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 80 (http)
2018-03-09 11:02:01.188 INFO 5036 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2018-03-09 11:02:01.190 INFO 5036 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.42