我正在一个 Spring boot 项目中工作,该项目具有不同的连接数据库的方式,在 dev 中,我仅使用 postgresql
驱动程序与它连接,对于 qa< /em> 和 prod,我需要通过 spring-cloud-gcp-starter-sql-postgresql
连接,因为我们有一个云环境。
因此,为了管理所有这些可能性,我正在使用 maven 中的配置文件来控制我的 Spring 配置文件。
但是我在我的配置文件声明中遇到了 spring cloud 的启动器依赖项问题,因为它们没有版本并且 maven 无法识别默认版本。
那么,我该如何解决这个问题?
有没有办法知道哪个是 starter 依赖项的默认版本,并将该信息保存在要在配置文件标签中使用的变量中?
任何想法都会有很大帮助。
感谢您的阅读和您的时间。向大家问好
答案 0 :(得分:0)
您可以安全地从您的个人资料中提取 dependencyManagement
。
import 此范围仅在
<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
...