簡體   English   中英

Spring Boot (Maven) 中的不兼容依賴項

[英]Incompatible dependencies in Spring Boot (Maven)

我已經開始使用Spring Boot創建一個 RESTful API 。 我已經有 2 年沒碰過Spring了。 我正在使用Maven 我有主要的class:

package com.tsakirogf.smartapi;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SmartapiApplication
{

    public static void main(String[] args)
    {
        SpringApplication.run(PeopleapiApplication.class, args);
    }

}

我有一個ControllerModelService 這是我的pom.xml

<?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.4.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.tsakirogf</groupId>
    <artifactId>peopleapi</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>smartapi</name>
    <description>Technical Test</description>
    <properties>
        <java.version>11</java.version>
<!--        <tomcat.version>8.5.63</tomcat.version>-->
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.200</version>
<!--            <scope>test</scope>-->
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>2.4.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>2.4.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.4.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-commons</artifactId>
            <version>2.3.6.RELEASE</version>
        </dependency>
    </dependencies>

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

該項目正在成功構建,並且mvn cleanmvn install命令也成功運行。 問題是,當我嘗試在IntelliJ中運行它時,出現此錯誤:

2021-02-11 18:19:42.692 ERROR 14584 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
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.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1355)

The following method did not exist:

    'java.lang.String javax.servlet.ServletContext.getVirtualServerName()'

The method's class, javax.servlet.ServletContext, is available from the following locations:

    jar:file:/F:/Workspace/Uni/SoftwareEngineer/peopleapi/lib/javax.servlet.jar!/javax/servlet/ServletContext.class
    jar:file:/C:/Users/Fotis/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.41/tomcat-embed-core-9.0.41.jar!/javax/servlet/ServletContext.class

The class hierarchy was loaded from the following locations:

    javax.servlet.ServletContext: file:/F:/Workspace/Uni/SoftwareEngineer/peopleapi/lib/javax.servlet.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext


Process finished with exit code 1

我應該采取什么想法或方向? 我嘗試同步依賴項並嘗試了pom中的最新和 RELEASE 包。 我還刪除了整個m2存儲庫(兩次)。

你的問題是 F:/Workspace/Uni/SoftwareEngineer/peopleapi/lib/javax.servlet.jar。 檢查你為什么在你的類路徑中有那個 JAR (很可能它來自一些腳本左右)。 這似乎比您在 pom.xml 中引用的版本舊

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM