本文介绍了我应该如何在 Spring boot 项目中更改战争的 Tomcat 版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Spring boot 项目中更改 Tomcat 版本的战争

How can I change Tomcat version of a war in Spring boot project

我用 Maven 创建了一个 spring 项目.我想更改嵌入式tomcat的版本.

I've created a spring project with Maven. I would like to change the version of embedded tomcat.

我应该如何修改 pom.xml 或 s/t?

How should I modify pom.xml or s/t?

pom.xml :我用 Maven 创建了一个 spring 项目.我想更改嵌入式tomcat的版本.

pom.xml :I've created a spring project with Maven. I would like to change the version of embedded tomcat.

我应该如何修改 pom.xml 或 s/t?

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

推荐答案

当你使用 spring-boot-stater-parent 时,你可以使用 tomcat.version 属性来控制Tomcat的版本.您已经在 pom.xml 文件中完成了此操作:

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>

简而言之,您已经在更改 Spring Boot 使用的 Tomcat 版本.

In short, you are already changing the version of Tomcat that Spring Boot uses.

默认情况下,Spring Boot 2.3.1 使用 Tomcat 9.0.x.如果您从 pom 文件中删除 ,则应使用 Tomcat 9.0.x,然后您的应用程序应该能够启动.如果要自定义此版本,则应保留 tomcat.version 属性,但使用与 Spring Boot 兼容的版本.建议使用最新的 Tomcat 9.0.x 版本.最近的 8.5.x 版本也可能适用.

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.

这篇关于我应该如何在 Spring boot 项目中更改战争的 Tomcat 版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 16:31