• SpringBoot中pom.xml不引入依赖, 怎么使用parent父项目的依赖


    在Spring Boot项目中,如果你想使用父项目的依赖,而不想在pom.xml中显式引入依赖,你可以使用Maven的继承机制。

    首先,确保你的Spring Boot项目是一个子项目,即它继承自一个父项目。要实现这一点,在pom.xml文件中,将元素设置为pom,并且在元素中指定父项目的坐标。

    以下是一个示例pom.xml文件,其中包含父项目的依赖:

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    4. <modelVersion>4.0.0</modelVersion>
    5. <groupId>com.example</groupId>
    6. <artifactId>my-spring-boot-project</artifactId>
    7. <version>1.0.0</version>
    8. <packaging>pom</packaging>
    9. <parent>
    10. <groupId>com.example</groupId>
    11. <artifactId>my-parent-project</artifactId>
    12. <version>1.0.0</version>
    13. </parent>
    14. <!-- Spring Boot Starter dependencies -->
    15. <dependencies>
    16. <dependency>
    17. <groupId>org.springframework.boot</groupId>
    18. <artifactId>spring-boot-starter-web</artifactId>
    19. </dependency>
    20. <!-- Add other Spring Boot dependencies as needed -->
    21. </dependencies>
    22. <!-- Other project configuration -->
    23. </project>

    在上面的示例中,我们指定了父项目的坐标,即com.example:my-parent-project:1.0.0。这将使Maven在构建时自动继承父项目的依赖

    在你的子项目中,只需按照正常的方式添加Spring Boot Starter和其他依赖项。Maven将会自动解析并包含父项目和所有依赖项。

    这样,你就可以使用父项目中的依赖项,而无需在子项目的pom.xml中显式引入它们。

  • 相关阅读:
    【Linux】常用命令
    redis使用
    基于安卓(Android)的即时实时聊天APP软件
    大数据信用报告如何查询?有哪些需要注意的?
    Monaco Editor 的基本用法
    天翼物联亮相2022中国信息通信业发展高层论坛
    阿里终面:10亿数据如何快速插入MySQL?
    基于JAVA的RSA文件加密软件的设计与实现
    MS17010利用方式
    快速掌握并发编程 --- 基础篇
  • 原文地址:https://blog.csdn.net/qq_44695727/article/details/133929768