How to change embedded tomcat's version in existing spring boot app?
Asked Answered
B

4

16

I'm currently running spring-boot version 1.4.0.RELEASE application with embedded tomcat. Included Tomcat's version is 8.5.4

There's a need to update the tomcat version to 9.x. When I looked at mvnrepository here, I found that there's an update available to tomcat version 9.0.5 (shown in pic below)

enter image description here

How should I use this version in my project if there's no way to directly mention this version in my pom.xml?

I do not want to go the traditional deployment route (WAR artifacts on external tomcats).

Berkie answered 9/3, 2018 at 11:1 Comment(3)
I doubt it would work, there have been internal changes in tomcat which aren't reflected in the code for Spring Boot 1.4.Proboscidean
OK. But is there a way to change that version at all? I am ready to upgrade spring-boot version to 2.0.0.RELEASE however that has tomcat version 8.5.28Berkie
Just specify the version you want to use (assuming you are using the spring-boot-starter-parent as the parent of your project.Proboscidean
S
25

If you are using spring boot gradle plugin and spring boot starters ..you can customise the version by setting maven project properties in build.gradle.

ext['tomcat.version'] = '9.0.45'

for maven

<properties>
    <tomcat.version>9.0.45</tomcat.version>
<properties>

You can find all the external dependencies that can be customised in spring-boot-dependencies

Suppressive answered 10/10, 2018 at 2:30 Comment(5)
Too bad you couldn't give the whole example of how to do it. This a partial answerKhan
Using gradle was able to by doing def tomcatVersion = '9.0.30' and dependencies { implementation "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}" implementation "org.apache.tomcat.embed:tomcat-embed-el:${tomcatVersion}" implementation "org.apache.tomcat.embed:tomcat-embed-websocket:${tomcatVersion}" implementation "org.apache.tomcat:tomcat-annotations-api:${tomcatVersion}" }Khan
If were using maven, add dependencies within <dependencyManagement>, otherwise project might not change it at all.Ramiah
I wouldn't give Tomcat 10 as an example, as it is jakartified and the current Spring libraries won't work with it.Rights
Does this still work in Maven with newer versions of Spring boot? It seems like there no longer exists a pom.xml to overwrite: github.com/spring-projects/spring-boot/tree/main/…Iddo
T
19

Late to the party I know, was looking for a similar issue, thought I'd share a more literal hint.

You need to override the properties set in spring's parent pom (which is mandatory for this) to suit your case (and compatibility too):

<properties>
......
    <tomcat.version>9.0.5</tomcat.version>
......
<properties>

This is according to [Introduction to Spring][1]. Their example shows many other dependencies cherry-picked. [1]: http://www.springboottutorial.com/spring-boot-starter-parent

Trihedral answered 18/7, 2018 at 15:49 Comment(0)
R
5

For maven projects

<properties>
  ...
  <tomcat.version>8.0.53</tomcat.version>
</properties>

<dependencyManagement>
        <dependencies>
         <!-- NON-INFORMATIVE -->
         <!--   <dependency>
                <groupId>io.spring.platform</groupId>
                <artifactId>platform-bom</artifactId>
                <version>${bom.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>   -->
            <dependency>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-core</artifactId>
                <version>${tomcat.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-el</artifactId>
                <version>${tomcat.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
Ramiah answered 21/4, 2021 at 17:57 Comment(0)
E
0

After changing the version by adding ext version in build gradle and trying to run application getting an error Getting Error: .... nested exception is java.lang.NoSuchMethodError: org.apache.catalina.Context.addServletMapping(Ljava/lang/String)

Epanorthosis answered 7/4, 2022 at 21:1 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Tatterdemalion

© 2022 - 2024 — McMap. All rights reserved.