我的springboot项目进行多环境配置,在pom.xml中,如下,我已经设置test为active,但是${profileActive}却总是指向dev,除非我把dev的profile删了,才会不情愿的指向test,这是怎么回事?
<profiles>
<profile>
<id>test</id>
<properties>
<profileActive>test</profileActive>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>dev</id>
<properties>
<profileActive>dev</profileActive>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profileActive>prod</profileActive>
</properties>
</profile>
</profiles>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>application.properties</exclude>
<exclude>application-dev.properties</exclude>
<exclude>application-test.properties</exclude>
<exclude>application-prod.properties</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>application.properties</include>
<include>application-${profileActive}.properties</include>
</includes>
</resource>
</resources>
其实maven注入最终也是走JVM的,因此我给你提供另一种方法,你这个方法的问题可能在于${env}上。
然后在启动类的JVM入参处动态控制运行环境
如你有dev,test,idc等配置文件,利用这种注入方式,指定哪个配置文件,服务就运行哪个环境,非常方便。