Reputation: 39
How can I change Tomcat version of a war in Spring boot project
I've created a spring project with Maven. I would like to change the version of embedded tomcat.
How should I modify pom.xml or s/t?
pom.xml : I've created a spring project with Maven. I would like to change the version of embedded tomcat.
How should I modify pom.xml or s/t?
pom.xml :
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<tomcat.version>8.5.32</tomcat.version>
</properties>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.xxxxx</groupId>
<artifactId>yyyy</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<name>xxxxx</name>
<description>Demo project for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<tomcat.version>8.5.32</tomcat.version>
</properties>
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:175)
The following method did not exist:
org.apache.tomcat.util.modeler.Registry.disableRegistry()V
jar:file:/C:/Users/moto/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.35/tomcat-embed-core-8.5.35.jar!/org/apache/tomcat/util/modeler/Registry.class
The class hierarchy was loaded from the following locations:
org.apache.tomcat.util.modeler.Registry: file:/C:/Users/moto/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.35/tomcat-embed-core-8.5.35.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.apache.tomcat.util.modeler.Registry
Upvotes: 0
Views: 7107
Reputation: 91
In my case, I had to remove the Tomcat library from the Java Build Path in Eclipse. The Tomcat 8.5.32 library had been added by default when I created the dynamic web project. I believe this was causing Spring Boot to use my Eclipse default instead of the correct Tomcat 9 as described in Andy Wilkinson's response.
Upvotes: 0
Reputation: 659
If the effective maven POM file shows the overridden tomcat version then next step to debug this issue is to manually delete the org/apache/tomcat/embed
in your .m2/repository
folder and build the project again.
If it still does not work then try adding the dependencies manually as you are trying to use the older version of tomcat (not recommended but for debugging sake )
org.apache.tomcat.embed tomcat-embed-core
org.apache.tomcat.embed tomcat-embed-el
org.apache.tomcat.embed tomcat-embed-jasper
org.apache.tomcat.embed tomcat-embed-websocket
Upvotes: 0
Reputation: 116051
When you're using spring-boot-stater-parent
as you are, you can use a tomcat.version
property to control the version of Tomcat. You've already done this in your pom.xml
file:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<tomcat.version>8.5.32</tomcat.version>
</properties>
In short, you are already changing the version of Tomcat that Spring Boot uses.
By default, Spring Boot 2.3.1 uses Tomcat 9.0.x. If you remove <tomcat.version>8.5.32</tomcat.version>
from your pom file, Tomcat 9.0.x should be used and your application should then be able to start. If you want to customise this version then you should keep the tomcat.version
property but use a version with which Spring Boot is compatible. The latest Tomcat 9.0.x release is recommended. Recent 8.5.x releases may also work.
Upvotes: 2