pom文件问题:更正应用程序的类路径,使其包含类 ?

作者站长头像
站长
· 阅读数 7

他推荐我的操作是:更正应用程序的类路径,使其包含类 org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory 和 org.apache.catalina.Context 的兼容版本

这是控制台的error


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.configureContext(TomcatServletWebServerFactory.java:381)

The following method did not exist:

    'void org.apache.catalina.Context.addServletContainerInitializer(jakarta.servlet.ServletContainerInitializer, java.util.Set)'

The calling method's class, org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory, was loaded from the following location:

    jar:file:/C:/Users/hp7/.m2/repository/org/springframework/boot/spring-boot/3.1.0/spring-boot-3.1.0.jar!/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.class

The called method's class, org.apache.catalina.Context, is available from the following locations:

    jar:file:/D:/apache-tomcat-9.0.70/lib/catalina.jar!/org/apache/catalina/Context.class

The called method's class hierarchy was loaded from the following locations:

    org.apache.catalina.Context: file:/D:/apache-tomcat-9.0.70/lib/catalina.jar


Action:

Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory and org.apache.catalina.Context

更正应用程序的类路径,使其包含类 org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory 和 org.apache.catalina.Context 的兼容版本

进程已结束,退出代码0
<?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>
    <packaging>war</packaging>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.0</version>
        <relativePath/>
    </parent>
    <groupId>com.example</groupId>
    <artifactId>vue02demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>vue02demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <quarkus.package.type>native</quarkus.package.type>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <maven.compiler.release>17</maven.compiler.release>
    </properties>


    <dependencies>
        <dependency>
            <groupId>org.bitbucket.b_c</groupId>
            <artifactId>jose4j</artifactId>
            <version>0.9.3</version>
            <exclusions>

                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.alibaba.fastjson2</groupId>
            <artifactId>fastjson2</artifactId>
            <version>2.0.33</version>
        </dependency>
        <!--jsp的依赖-->
        <dependency>
            <groupId>jakarta.servlet.jsp</groupId>
            <artifactId>jakarta.servlet.jsp-api</artifactId>
            <version>3.0.0</version>
            <scope>provided</scope>
        </dependency>

        <!--jar包的依赖-->
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <version>6.0.0</version>
            <scope>provided</scope>
        </dependency>


        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
            <version>4.5.14</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>com.nimbusds</groupId>
            <artifactId>nimbus-jose-jwt</artifactId>
            <version>9.30.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.14</version>
        </dependency>
        <!--常用工具-->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.11</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
            <version>3.0.4</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.10.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
            <version>3.0.4</version>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.8.15</version>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-starter-web</artifactId>-->
<!--            <version>3.1.0</version>-->
<!--            <exclusions>-->
<!--                &lt;!&ndash; Exclude the Tomcat dependency &ndash;&gt;-->
<!--                <exclusion>-->
<!--                    <groupId>org.springframework.boot</groupId>-->
<!--                    <artifactId>spring-boot-starter-tomcat</artifactId>-->
<!--                </exclusion>-->
<!--            </exclusions>-->
<!--        </dependency>-->

        <dependency>
            <groupId>com.auth0</groupId>
            <artifactId>java-jwt</artifactId>
            <version>4.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>3.0.2</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <version>3.0.4</version>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.26</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>6.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>6.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.surefire</groupId>
            <artifactId>surefire-booter</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>com.akamai</groupId>
            <artifactId>EdgeAuth-Token-Java</artifactId>
            <version>0.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.zdawn</groupId>
            <artifactId>jwt-token</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>com.zdawn</groupId>
            <artifactId>jwt-token-redis</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>3.2.1</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.10.1</version>
        </dependency>
        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>js-tokens</artifactId>
            <version>8.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.abasecode.opencode</groupId>
            <artifactId>abasecode-base-token</artifactId>
            <version>1.1.0</version>
        </dependency>



        <dependency>
            <groupId>cn.spark2fire.alberti</groupId>
            <artifactId>auth-redis</artifactId>
            <version>0.0.10</version>
        </dependency>
        <dependency>
            <groupId>cn.spark2fire.alberti</groupId>
            <artifactId>auth-jwt</artifactId>
            <version>0.0.10</version>
        </dependency>
        <dependency>
            <groupId>org.moara.yido</groupId>
            <artifactId>tokenizer</artifactId>
            <version>0.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.webjars.bowergithub.lydell</groupId>
            <artifactId>js-tokens</artifactId>
            <version>4.0.0</version>
        </dependency>
        <dependency>
            <groupId>cn.spark2fire.alberti</groupId>
            <artifactId>auth-core</artifactId>
            <version>0.0.10</version>
        </dependency>
        <dependency>
            <groupId>cn.spark2fire.alberti</groupId>
            <artifactId>auth-db</artifactId>
            <version>0.0.10</version>
        </dependency>
        <dependency>
            <groupId>io.github.fluxroot</groupId>
            <artifactId>result</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.github.kittinunf.result</groupId>
            <artifactId>result</artifactId>
            <version>5.3.0</version>
        </dependency>
        <dependency>
            <groupId>tech.favware</groupId>
            <artifactId>result</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.markelliot.result</groupId>
            <artifactId>result</artifactId>
            <version>0.37.0</version>
        </dependency>
        <dependency>
            <groupId>int.esa.ccsds.mo</groupId>
            <artifactId>ENCODING_STRING</artifactId>
            <version>8.0</version>
        </dependency>
        <dependency>
            <groupId>com.noelherrick.jell</groupId>
            <artifactId>jell</artifactId>
            <version>0.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>sell</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>int.esa.ccsds.mo</groupId>
            <artifactId>ENCODING_STRING</artifactId>
            <version>8.0</version>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>com.noelherrick.jell</groupId>
            <artifactId>jell</artifactId>
            <version>0.1.1</version>
            <scope>import</scope>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <verbose>true</verbose>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
回复
1个回答
avatar
test
2024-07-01

你的操作是正确的,你是打算更正应用程序的类路径,从而来包含 Tomcat Web 服务器所需的所有类。但是你应该遇到了兼容问题 根据报错的英文翻译过来的意思是“版本兼容性有问题,该方法在调用时需要 org.apache.catalina.Context 类的 addServletContainerInitializer() 方法,但是 addServletContainerInitializer() 方法在您的应用程序中并不存在”answer image 因此你可以检查应用程序的依赖项和版本,确保它们与 Tomcat 版本兼容,并尝试更正类路径。如果问题仍然存在,我建议你可以尝试升级依赖项版本或更换更新的 Tomcat 版本。

回复
likes
适合作为回答的
  • 经过验证的有效解决办法
  • 自己的经验指引,对解决问题有帮助
  • 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
  • 询问内容细节或回复楼层
  • 与题目无关的内容
  • “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容