gpt4 book ai didi

java - 从其他属性文件中替换 application.properties 的值

转载 作者:行者123 更新时间:2023-11-30 05:34:59 26 4
gpt4 key购买 nike

我的 Spring boot 应用程序中有以下文件应用程序属性文件。所有属性文件都位于 src/main/resources 文件夹中Spring Boot版本为2.1.6

application.properties application-dev.properties application-tst.properties

application.properties app.name={app.name} app.common=Common val
application-dev.properties app.name=My dev app
application-tst.properties app.name=My tst app

Dev 和 tst 是我创建的 Maven 配置文件

 <profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<env>dev</env>
</properties>
</profile>

<profile>
<id>tst</id>
<properties>
<env>tst</env>
</properties>
</profile>
</profiles>

如果我使用开发配置文件构建项目,我应该在我的 application.properties 中获得以下内容

1)mvn -Pdev clean install

application.properties app.name=My dev app app.common=Common val

2)mvn -Ptst clean install

application.properties app.name=My tst app app.common=Common val

我怎样才能实现这个目标?

最佳答案

您可以使用环境变量来设置 Activity 配置文件,如下所示

mvn install -Dspring.profiles.active=dev

mvn install -Dspring.profiles.active=tst

关于java - 从其他属性文件中替换 application.properties 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56832794/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com