【发布时间】:2020-07-02 12:49:02
【问题描述】:
我需要根据 Spring Boot Maven 应用程序中的环境细节激活配置文件。我在 settings.xml
中配置了配置文件 <profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>false</activeByDefault> </activation>
<repositories>
<repository>
<id>devRepo</id>
<url>https://customRepo/maven/v1</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>qa</id>
<activation>
<activeByDefault>false</activeByDefault> </activation>
<repositories>
<repository>
<id>qaRepo</id>
<url>https://customRepo2/maven/v1</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
我尝试使用命令-Pdev 激活配置文件
mvn spring-boot:run -s settings.xml -D"spring-boot.run.profiles"=dev help:active-profiles
但配置文件未正确激活。 但是通过添加 activeprofiles 标签可以正常工作。
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
但我需要激活特定的配置文件环境,例如
<activeProfiles>
<activeProfile>$env</activeProfile>
</activeProfiles>
我们可以通过任何方式将参数传递给 settings.xml 文件中的activeProfile 吗?类似这样-Denv
参考:
Maven: How do I activate a profile from command line?
Configure active profile in SpringBoot via Maven
【问题讨论】: