0

The requirement is to use spring boot version 2.2.6.RELEASE however the tomcat version should be 9.0.37.

I tried to do it by excluding the tomcat starter from the spring-boot-starter-web depdendency like so :

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <version>${spring-boot.version}</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-logging</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

And added the spring-boot-starter-tomcat separately which has the 9.0.37 tomcat version :

         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <version>2.3.2.RELEASE</version>
        </dependency>

However even after doing so the version is not override and the following gets used :

Mar 11 2020 09:31:38 UTC
Apache Tomcat/9.0.33
9.0.33.0

Do we need to do anything else to override the tomcat version? Is it possible to override it by excluding started?

Update: The parent pom is a corporate parent pom and not the spring-boot-starter-parent. As per one of the answers we can simply override the tomcat.version property however my effective pom doesn't show it.

humbleCoder
  • 667
  • 14
  • 27
  • 1
    Does this answer your question? [How to change embedded tomcat's version in existing spring boot app?](https://stackoverflow.com/questions/49192295/how-to-change-embedded-tomcats-version-in-existing-spring-boot-app) – Clijsters Jul 27 '20 at 08:12
  • Don't. Never mix modules of different versions of a framework, that will lead to issues. Just change the version as explained in the reference guide [here](https://docs.spring.io/spring-boot/docs/2.3.2.RELEASE/maven-plugin/reference/html/#using-parent-pom) for a list of version properties to override see [this appendix](https://docs.spring.io/spring-boot/docs/2.3.2.RELEASE/reference/htmlsingle/#dependency-versions-properties) – M. Deinum Jul 27 '20 at 08:19
  • Great I think this is the way to do it. Will try it today! – humbleCoder Jul 28 '20 at 04:27
  • Its just not working :-( Is there a sample application demo for this somewhere? – humbleCoder Aug 03 '20 at 09:49

2 Answers2

2

If you're not inheriting from spring-boot-starter-parent I can only guess that you import spring-boot-dependencies in your dependencies management somewhere.

The documentation covers what you need to do to override the tomcat version. Each tomcat artifact should be listed with the overridden version, before you imports spring-boot-dependencies. The list of artifacts can be found in spring-boot-dependencies.

Using a different version of the starter is wrong (you can't mix two Spring Boot versions in the same app) and will have no effect since dependency management is in control anyway. In other words, you'll get spring-boot-starter-web version 2.3.2.RELEASE indeed but all the artefacts that it brings will be managed by the dependency management (the tomcat version defined by version 2.2.6.RELEASE).

In that particular case of yours, upgrading to 2.2.9.RELEASE could also be an option as it provides dependency management for the tomcat version that you need.

Stephane Nicoll
  • 31,977
  • 9
  • 97
  • 89
  • Thanks for the explanation. Now I get it. – humbleCoder Aug 03 '20 at 11:18
  • Just one thing, I added all the required tomcat dependencies in the dependency management tag and it worked. Just that it doesn't matter if I add it before the spring boot dependencies import dependency or after, in both cases I am able to override the tomcat version. However the documentation states that it should before the spring boot dependencies tag. Any reason why we have to add it before the tag or what am I missing? – humbleCoder Aug 04 '20 at 04:16
0

Well, this has been already answered.

For you, as you are using maven, you need to override the properties set in parent Spring pom.

<properties>
  ......
<tomcat.version>your_version</tomcat.version>
  ......
<properties>

For gradle, it is simple as

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

in your main build.gradle

Source: How to change embedded tomcat's version in existing spring boot app?

iamceph
  • 11
  • 4
  • The effective pom doesn't have any property namely tomcat.version and simply overriding it doesn't work for me. May be it was available in older versions of spring boot i.e. is before boot 2. – humbleCoder Jul 27 '20 at 07:27
  • It seems that it is still the same - https://stackoverflow.com/questions/62826247/how-should-i-change-tomcat-version-of-a-war-in-spring-boot-project But I am using Gradle for most parts so I can't help that much – iamceph Jul 27 '20 at 07:30
  • Oh its there when I manually traverse the poms and check in spring-boot-dependencies pom then I can see the property. But it doesn't show up in effective pom. We have a company wide parent pom as our parent pom instead of spring parent as the parent (which is there as a dependency) does that make a difference? I though it combines the properties of all poms. – humbleCoder Jul 27 '20 at 07:37
  • I would suggest for that company parent to add parent to `spring-boot-starter-parent`. Then you can edit the version - that is probably why it is not working for you. – iamceph Jul 27 '20 at 07:53
  • You mean the company poms parent should be changed to spring-boot-starter-parent? – humbleCoder Jul 27 '20 at 08:00
  • No, no, the main parent should be linked to spring parent via ` org.springframework.boot spring-boot-starter-parent 2.3.1.RELEASE ` – iamceph Jul 27 '20 at 08:31
  • We cant change the parent pom as its not in our control and multiple project use it. The second comment on the question post seems to be the way to go. Its not working for me but will check in more detail today. – humbleCoder Jul 28 '20 at 04:22
  • Alright, make sure to let me know what was the problem, I would love to know :) – iamceph Jul 28 '20 at 08:15