Spring boot Maven 中某些依赖项出现依赖错误

问题描述 投票:0回答:2
java spring-boot maven
2个回答
0
投票

通常,当您在 POM 中定义了

dependencyManagement
部分(其中集中了所有模块使用的所有依赖项)时,您不会声明依赖项版本。

由于您的 POM 未定义

dependencyManagement
,因此您需要提供每个依赖项的版本。您可以从 Spring Boot 检查此示例指南项目,您会注意到它们在 POM 中设置了父级:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.2</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

此父级将导致 POM 继承包含 dependencyManagement

 依赖项的所有版本的 
spring-boot-starter-xx
 部分

更多详细信息:https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-dependency-management


0
投票

补充一下,以下内容不起作用:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.2.3</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
 <dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            </dependency>
    </dependencies>
</dependencyManagement>

您必须在 dependencyManagement 中提供版本,因为您要覆盖父 dependencyManagement 的行为。 更正代码:

<dependencyManagement>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <version>3.2.3</version>
    </dependency>
</dependencies>
© www.soinside.com 2019 - 2024. All rights reserved.