【问题标题】:Correction of the classpath of your application that should contains a single, compatible version更正应包含单个兼容版本的应用程序的类路径
【发布时间】:2021-01-05 03:41:55
【问题描述】:

我有一个问题。试图更改版本(就像它在互联网上所说的那样),但它没有帮助。我已经阅读了这些答案Correct the classpath of your application so that it contains a single, compatible version of org.springframework.plugin.core.PluginRegistry,但也没有用。

问题:

更正应用程序的类路径,使其包含一个兼容的 org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter 版本

控制台:

***************************
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.autoconfigure.http.HttpMessageConverters.configurePartConverters(HttpMessageConverters.java:140)

The following method did not exist:

    'java.util.List org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.getPartConverters()'

The method's class, org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter, is available from the following locations:

    jar:file:/C:/Users/1/.m2/repository/org/springframework/spring-web/5.2.8.RELEASE/spring-web-5.2.8.RELEASE.jar!/org/springframework/http/converter/support/AllEncompassingFormHttpMessageConverter.class

The class hierarchy was loaded from the following locations:

    org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter: file:/C:/Users/1/.m2/repository/org/springframework/spring-web/5.2.8.RELEASE/spring-web-5.2.8.RELEASE.jar
    org.springframework.http.converter.FormHttpMessageConverter: file:/C:/Users/1/.m2/repository/org/springframework/spring-web/5.2.8.RELEASE/spring-web-5.2.8.RELEASE.jar

Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter

我的 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.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example.alpha</groupId>
    <artifactId>bank</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>bank</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.2.3.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.2</version>
            <scope>provided</scope>
        </dependency>

            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.11.3</version>
            </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

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

</project>

【问题讨论】:

  • Spring Boot 的部分工作是管理依赖版本。您不应该在 POM 中为任何 dependency 条目包含 version 标签; Boot 已经为您指定了正确的。
  • 此外,自 2.4.0 以来的 spring-boot 仅使用 JUnit Jupiter 而不是 JUnit 4,因此更好地切换到 JUnit Jupiter 而不是 JUnit 4 ... 还删除已经提到的 spring-web 的版本。 ..对于龙目岛(真的需要那个?)和杰克逊...保留spring-boot提供的版本

标签: java spring-boot maven


【解决方案1】:

由于 maven 为我们管理来自指定父项目 spring-boot-starter-parent 的正确依赖层次结构,因此我们不再需要为像 &lt;version&gt;5.2.3.RELEASE&lt;/version&gt; 这样的子项目指定版本信息在您的情况下,以下依赖项:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>5.2.3.RELEASE</version>
</dependency>

【讨论】:

    【解决方案2】:

    我通过添加下面的 Maven 依赖项来解决问题,当我们从 start.spring.io 下载时,默认情况下它似乎合理地位于 pom 中,但它不存在。

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    

    【讨论】:

    • 非常感谢:}这只对我有用
    猜你喜欢
    • 1970-01-01
    • 2022-01-01
    • 2021-06-29
    • 2019-08-11
    • 2021-07-08
    • 2021-11-07
    • 2021-04-14
    • 1970-01-01
    相关资源
    最近更新 更多