除默认配置文件外,Maven 配置文件未激活
Maven profiles are not activating except default profile
我正在开发 spring-boot 应用程序。我的 POM 中有两个配置文件,但是当我尝试使用 clean install -Pdev 构建项目时,它不会反映 application.properties 中的更改,它只会反映在我使用 'activeByDefault' 标记时个人资料之一。
<profiles>
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
</properties>
</profile>
<profile>
<id>release</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<activatedProperties>release</activatedProperties>
</properties>
</profile>
</profiles>
如果我 运行 clean install -Pdev 我会在我的 application.properties 中得到这个。
activatedProperties=@activatedProperties@
如果我设置 <activeByDefault>true</activeByDefault>
,那么我将获得 application.properties 中的值。
activatedProperties=release.
令人沮丧的是我无法使用其他配置文件。
加入你的application.properties
spring.profiles.active=@activatedProperties@
如果 Maven 在运行时找不到包含您的 application.properties 文件的目录,您需要设置 Maven 资源插件来过滤该目录。
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
...
</build>
或者只需在 application.properties
中添加您想要激活的配置文件
spring.profiles.active=dev
注意: Maven 配置文件和 Spring 配置文件是不同的东西。
我正在开发 spring-boot 应用程序。我的 POM 中有两个配置文件,但是当我尝试使用 clean install -Pdev 构建项目时,它不会反映 application.properties 中的更改,它只会反映在我使用 'activeByDefault' 标记时个人资料之一。
<profiles>
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
</properties>
</profile>
<profile>
<id>release</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<activatedProperties>release</activatedProperties>
</properties>
</profile>
</profiles>
如果我 运行 clean install -Pdev 我会在我的 application.properties 中得到这个。 activatedProperties=@activatedProperties@
如果我设置 <activeByDefault>true</activeByDefault>
,那么我将获得 application.properties 中的值。
activatedProperties=release.
令人沮丧的是我无法使用其他配置文件。
加入你的application.properties
spring.profiles.active=@activatedProperties@
如果 Maven 在运行时找不到包含您的 application.properties 文件的目录,您需要设置 Maven 资源插件来过滤该目录。
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
...
</build>
或者只需在 application.properties
中添加您想要激活的配置文件spring.profiles.active=dev
注意: Maven 配置文件和 Spring 配置文件是不同的东西。