我有一个具有dev和prod设置的spring boot应用程序。遵循在搜索过程中找到的多条指令,我有一个application.properties文件,该文件具有:
#-----------this will load the prod or dev according to the @activatedProperties@ value which is set from the pom when built
spring.profiles.active=@activatedProperties@
然后有两个文件:
- application-dev.properties
- application.prod.properties
然后我有一个pom,它以spring-boot pom作为父项
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
然后我将配置文件设置如下:
<profiles>
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>prod</id>
<properties>
<activatedProperties>prod</activatedProperties>
</properties>
</profile>
</profiles>
如果我然后按如下所示执行构建:
mvn -DskipTests -Pprod clean compile package
完成此操作后,application.properties文件显示:
#-----------this will load the prod or dev according to the environment
spring.profiles.active=dev
请注意,它没有按要求使用prod,而是使用dev。实际上,无论我做什么,它都只是执行activeByDefault配置文件。有没有其他人看到这一点,对发生的事情有任何想法。正如您可以想象的那样,让部署说明说“编辑POM文件以将activeByDefault属性从dev移到prod配置文件”确实很烦人!