您现在的位置是:首页 > Javascript
当前栏目
Spring boot自定义parent POM
2023-04-18 13:09:19 时间
概述
在之前的Spring Boot例子中,我们都会用到这样的parent POM。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
这个parent指定了spring-boot所需要的依赖。但是有时候如果我们的项目已经有一个parent了,这时候需要引入spring boot该怎么处理呢?
本文将会解决这个问题。
不使用Parent POM来引入Spring boot
parent pom.xml主要处理的是依赖和使用的插件管理。使用起来会非常简单,这也是我们在Spring boot中常用的方式。
在实际中,如果我们因为种种原因,不能使用Spring boot自带的parent,那么我们可以这样做:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
将spring-boot-dependencies作为一个依赖放入dependencyManagement标签即可。注意,这里的scope要使用import。
接下来,我们就可以随意使用spring boot的依赖了,例如:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
另一方面,如果不使用parent POM,Spring boot自带的plugin,需要我们自己引入:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
覆盖依赖项版本
如果我们需要使用和parent POM中定义的不同的依赖项版本,则可以在dependencyManagement中重写。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>1.5.5.RELEASE</version>
</dependency>
</dependencies>
// ...
</dependencyManagement>
当然,你也可以在每次引入依赖的时候,指定所需要的版本。
更多教程请参考 flydean的博客
相关文章
- 【Web 三件套】个人简单博客系统页面搭建(附源码)
- vue开发页面自适应屏幕尺寸
- Vue-cli(vue脚手架)上万字总结,超详细教程
- Vue3预览并打印PDF的两种方法
- nvm安装步骤
- 快看,他纯用css绘制出了嫦娥手捧的月兔,关键还能飞,牛
- 权限管理实现的两种方式(详解)
- 一个简单的网页设计HTML5作业
- VUE框架
- 前端实现分页效果
- 【Vue面试专题】50+道经典Vue面试题详解!
- elementUI自定义上传文件(前端后端超详细过程)
- vue-devtools的安装与使用
- 一文详解 Netty 组件
- 2023 Vue前端面试题
- html中常见标签及其用法归纳大全
- (详解错误情况,及解决方法)Vue 数据更新了但页面没有更新的情况
- Java+Jquer实现趋势图
- 什么是axios(写给小白的理解笔记)
- 【TypeScript】TS进阶-函数重载(七)