构建 Spring 引导的冲突问题

Conflict problem building the Spring boot

我在构建 spring 引导应用程序时遇到问题。我们需要使用 Maven 构建具有 'lib/bin/conf' 结构的项目。我用另一个项目做的,没有问题。但是现在,发生了冲突,建议采取措施。

***************************
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.beans.factory.support.DefaultSingletonBeanRegistry.<init>(DefaultSingletonBeanRegistry.java:88)

The following method did not exist:

    'java.util.Map org.springframework.core.CollectionFactory.createConcurrentMapIfPossible(int)'

The calling method's class, org.springframework.beans.factory.support.DefaultSingletonBeanRegistry, is available from the following locations:

    jar:file:/Users/user/.m2/repository/org/springframework/spring/2.5.5/spring-2.5.5.jar!/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.class
    jar:file:/Users/user/.m2/repository/org/springframework/spring-beans/5.3.18/spring-beans-5.3.18.jar!/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.class

The calling method's class was loaded from the following location:

    file:/Users/user/.m2/repository/org/springframework/spring/2.5.5/spring-2.5.5.jar

The called method's class, org.springframework.core.CollectionFactory, is available from the following locations:

    jar:file:/Users/user/.m2/repository/org/springframework/spring-core/5.3.18/spring-core-5.3.18.jar!/org/springframework/core/CollectionFactory.class
    jar:file:/Users/user/.m2/repository/org/springframework/spring/2.5.5/spring-2.5.5.jar!/org/springframework/core/CollectionFactory.class

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

    org.springframework.core.CollectionFactory: file:/Users/user/.m2/repository/org/springframework/spring-core/5.3.18/spring-core-5.3.18.jar


Action:

Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.beans.factory.support.DefaultSingletonBeanRegistry and org.springframework.core.CollectionFactory


我该如何解决这个问题?公司提供的部分库已被删除。这是我的 pom 文件。

<?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.6.6</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>...</groupId>
    <artifactId>...</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>...</name>

    <properties>
        <java.version>11</java.version>
        <finalName>${project.artifactId}-${project.version}</finalName>
        <logback.version>1.2.9</logback.version>
        <log4j.version>2.17.0</log4j.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-batch</artifactId>
        </dependency>
        <dependency>
            <groupId>net.javacrumbs.shedlock</groupId>
            <artifactId>shedlock-spring</artifactId>
            <version>4.34.0</version>
        </dependency>
        <dependency>
            <groupId>net.javacrumbs.shedlock</groupId>
            <artifactId>shedlock-provider-jdbc-template</artifactId>
            <version>4.34.0</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <!-- vault -->
        <dependency>
            <groupId>org.springframework.vault</groupId>
            <artifactId>spring-vault-core</artifactId>
            <version>2.2.2.RELEASE</version>
        </dependency>

        <!-- log4j -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>${log4j.version}</version>
        </dependency>

        <!-- logback -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>${logback.version}</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
        </dependency>

        <!-- Swagger 2 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>

        <!-- Apache Commons -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.11</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.8.0</version>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.4</version>
        </dependency>

        <dependency>
            <groupId>io.lettuce</groupId>
            <artifactId>lettuce-core</artifactId>
            <version>5.2.2.RELEASE</version>
        </dependency>

        <!--proxy-->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.4.13</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>${finalName}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

DefaultSingletonBeanRegistry 和 CollectionFactory 在 spring-2.5.5 中是重复的,实际上它们已经包含在 spring-beans 和 spring-core.

执行'mvn dependency:tree -Dverbose'看spring-2.5.5是如何被包含的,排除再试

Spring2.5.5has been obsolete for 12 years;你没有理由拥有它。此外,在 Maven 中使用 lib 目录绝对没有任何意义;依赖管理是 Maven 的大部分功能 for.

我在您的 POM 中看不到任何可以引入 Spring 2.5.5 的内容。是否有可能与您的项目相关的其他内容打错了字并打算包含 Spring Boot 2.5.5?在任何情况下,确定这是从哪里来的 (mvn dependency:tree) 并修复它。