我正在开发一个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=发布。
令人沮丧的是,我无法使用其他个人资料。
添加到您的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概要文件是不同的。