当前位置: 首页 > news >正文

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

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

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

以下是一个示例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 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.example</groupId><artifactId>my-spring-boot-project</artifactId><version>1.0.0</version><packaging>pom</packaging><parent><groupId>com.example</groupId><artifactId>my-parent-project</artifactId><version>1.0.0</version></parent><!-- Spring Boot Starter dependencies --><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- Add other Spring Boot dependencies as needed --></dependencies><!-- Other project configuration --></project>

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

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

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

http://www.lryc.cn/news/198865.html

相关文章:

  • 基于vue3+ts5+vue-router4+pinia2的PC端项目搭建教程
  • 6个无版权、免费、高清图片素材库
  • 什么是响应式设计?响应式设计的基本原理是什么?如何兼容低版本的 IE?
  • LeetCode 2906. 构造乘积矩阵【前后缀分解,数组】中等
  • vue3+koa+axios实现前后端通信
  • Required MultipartFile parameter ‘file‘ is not present
  • vue3后台管理系统之layout组件的搭建
  • Minio 文件上传(后端处理同文件判断,同一文件秒传)
  • 模拟IIC通讯协议(stm32)(硬件iic后面在补)
  • 使用注解读取properties配置文件
  • Python---练习:求世界杯小组赛的总成绩(涉及:布尔类型转换为整型)
  • vue3学习源码笔记(小白入门系列)------KeepAlive 原理
  • 边写代码边学习之mlflow
  • 基于吉萨金字塔建造优化的BP神经网络(分类应用) - 附代码
  • axios的post请求所有传参方式
  • 【c++】向webrtc学比较2: IsNewerSequenceNumber 用于NackTracker及测试
  • PRCV 2023:语言模型与视觉生态如何协同?合合信息瞄准“多模态”技术
  • 深度学习硬件配置推荐(kaggle学习)
  • 1019hw
  • 两分钟搞懂UiAutomator自动化测试框架
  • Fast DDS之Subscriber
  • 测试PySpark
  • C语言- 原子操作
  • 设置hadoop+安装java环境
  • 阿里云新加坡主机服务器选择
  • 21天打卡掌握java基础操作
  • SQL题目记录
  • Linux程序调试器——gdb的使用
  • 前端打包项目上线-nginx
  • 创龙瑞芯微RK3568参数修改(调试口波特率和rootfs文件)