15

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).

shankulk
  • 534
  • 1
  • 4
  • 23
  • I doubt it would work, there have been internal changes in tomcat which aren't reflected in the code for Spring Boot 1.4. – M. Deinum Mar 09 '18 at 11:10
  • 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.28` – shankulk Mar 10 '18 at 09:18
  • Just specify the version you want to use (assuming you are using the `spring-boot-starter-parent` as the parent of your project. – M. Deinum Mar 12 '18 at 07:18

4 Answers4

20

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

Thilak
  • 656
  • 7
  • 15
  • 1
    Too bad you couldn't give the whole example of how to do it. This a partial answer – Shrikant Prabhu Jan 31 '20 at 01:40
  • 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}" }` – Shrikant Prabhu Jan 31 '20 at 17:14
  • If were using maven, add dependencies within ``, otherwise project might not change it at all. – Felix Aballi Apr 21 '21 at 17:53
  • I wouldn't give Tomcat 10 as an example, as it is jakartified and the current Spring libraries won't work with it. – Piotr P. Karwasz Apr 23 '21 at 05:51
  • Does this still work in Maven with newer versions of Spring boot? It seems like there no longer exists a `pom.xml` to overwrite: https://github.com/spring-projects/spring-boot/tree/main/spring-boot-project/spring-boot-dependencies – kashev Nov 02 '22 at 19:40
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

thi gg
  • 1,969
  • 2
  • 22
  • 47
ptrk
  • 1,800
  • 1
  • 15
  • 24
4

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>
Felix Aballi
  • 899
  • 1
  • 13
  • 31
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)

  • 2
    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](/help/how-to-answer). – Community Apr 08 '22 at 07:05