更改使用Spring Starter嵌入式Tomcat的版本

huangapple go评论80阅读模式
英文:

Change the version of the embedded tomcat using spring starter

问题

要求使用Spring Boot版本为2.2.6.RELEASE,但Tomcat版本应为9.0.37。

我尝试通过从spring-boot-starter-web依赖中排除Tomcat starter来实现:

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

然后单独添加了spring-boot-starter-tomcat,其中包含9.0.37版本的Tomcat:

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

然而,即使这样做,版本仍未覆盖,仍然使用以下版本:

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

我们需要采取其他措施来覆盖Tomcat版本吗?是否可以通过排除的方式覆盖它?

更新:
父POM是公司的父POM,而不是spring-boot-starter-parent。根据其中一个答案,我们可以简单地覆盖tomcat.version属性,但我的有效POM中没有显示它。

英文:

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 :

            &lt;dependency&gt;
				&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
				&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
				&lt;version&gt;${spring-boot.version}&lt;/version&gt;
				&lt;exclusions&gt;
					&lt;exclusion&gt;
						&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
						&lt;artifactId&gt;spring-boot-starter-logging&lt;/artifactId&gt;
					&lt;/exclusion&gt;
					&lt;exclusion&gt;
						&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
						&lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
					&lt;/exclusion&gt;
				&lt;/exclusions&gt;
			&lt;/dependency&gt;

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

         &lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
			&lt;version&gt;2.3.2.RELEASE&lt;/version&gt;
		&lt;/dependency&gt;

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.

答案1

得分: 2

如果您没有从 spring-boot-starter-parent 继承,我只能猜测您在依赖管理中导入了 spring-boot-dependencies

文档涵盖了您需要执行的操作,以覆盖 Tomcat 版本。每个 Tomcat 构件都应在被覆盖的版本下列出,然后才导入 spring-boot-dependencies。构件的列表可以在 spring-boot-dependencies 中找到。

使用不同版本的启动器是错误的(在同一个应用程序中不能混用两个 Spring Boot 版本),并且不会产生任何效果,因为依赖关系管理已经控制着它。换句话说,确实会得到 spring-boot-starter-web 版本 2.3.2.RELEASE,但它带来的所有构件都将由依赖关系管理(由版本 2.2.6.RELEASE 定义的 Tomcat 版本)进行管理。

在您的情况下,升级到 2.2.9.RELEASE 也可能是一个选项,因为它为您需要的 Tomcat 版本提供了依赖关系管理。

英文:

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.

答案2

得分: 0

好的,以下是翻译好的内容:

这个问题已经得到了解答。

对于您,因为您正在使用 Maven,您需要覆盖在父 Spring pom 中设置的属性。

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

对于 Gradle 来说,操作很简单,只需要在您的主 build.gradle 文件中添加如下代码:

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

来源:https://stackoverflow.com/questions/49192295/how-to-change-embedded-tomcats-version-in-existing-spring-boot-app

英文:

Well, this has been already answered.

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

&lt;properties&gt;
  ......
&lt;tomcat.version&gt;your_version&lt;/tomcat.version&gt;
  ......
&lt;properties&gt;

For gradle, it is simple as

ext[&#39;tomcat.version&#39;] = &#39;8.5.34&#39;

in your main build.gradle

Source: https://stackoverflow.com/questions/49192295/how-to-change-embedded-tomcats-version-in-existing-spring-boot-app

huangapple
  • 本文由 发表于 2020年7月27日 15:15:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/63110403.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定