java - 如何使用配置文件 maven 指定 Spring Boot 启动器依赖项的版本?
问题描述
我在一个 Spring boot 项目中工作,它有不同的方式连接数据库,在dev中我只用postgresql
驱动程序连接它,而对于qa和prod,我需要通过连接,spring-cloud-gcp-starter-sql-postgresql
因为我们有一个云环境。
因此,为了管理所有这些可能性,我正在使用 maven 中的配置文件来控制我的 Spring 配置文件。
但是我在我的个人资料声明中放置了 spring cloud 的启动器依赖项,因为它们没有版本并且 maven 无法识别默认版本。
那么,我该如何解决这个问题呢?
有没有办法知道哪个是启动器依赖项的默认版本并将该信息保存在要在配置文件标签中使用的变量中?
任何想法都会有很大帮助。
感谢您的阅读和您的时间。祝福大家
解决方案
您可以安全地dependencyManagement
从您的个人资料中提取。
参考:依赖范围
import此范围仅受该部分中 pom 类型的依赖项支持
<dependencyManagement>
。它表示依赖项将被指定 POM<dependencyManagement>
部分中的有效依赖项列表替换。由于它们被替换,具有导入范围的依赖项实际上并不参与限制依赖项的传递性。
因此,您可以安全地从您的配置文件中提取 dependencyManagement。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<profiles>
<profile>
<id>prod</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
</dependency>
</dependencies>
</profile>
...
</profiles>
或者您可以自己提供已解决的版本;因为Greenwich.SR2
那将是1.1.2.RELEASE
...
推荐阅读
- python - 在 Python 中使用特征值约束优化目标函数
- python-3.x - 调试一段很简单的python代码,看到了意想不到的结果,只想知道为什么会这样
- unity3d - 物理相机视口应根据 UI 调整以适应不同的分辨率
- python - 迁移到 Ubuntu 后查询的 SQL ROW_NUMBER() 问题
- php - 如何在 Debian 9 机器上为 PHP 7.3 安装 php-fpm?
- assembly - 汇编 - 机器代码中的跳转指令
- python - 将颜色设置为 2d 散点图点 - Matplotlib
- c# - 以编程方式将管理员帐户降级为访客帐户
- javascript - 单击图标以展开模式中的图像
- java - 为什么这个 LCS 算法会产生每个元素的多个重复项?