目前主流的springboot项目设置了提供了springboot spring.profiles.active支持多环境下,几套配置文件切换。用起来已经非常方便
在传统的springmvc项目没使用pom profile时,我是在spring application.xml加载properties时选择加载哪个配置文件。这样切换频繁的修改spring application.xml文件也能实现。
这种方式在项目打包后xml文件是和源码一样的,在项目启动时,spring加载对应的配置文件填充 ${}属性
maven也提供了 pom文件通过profile配置多环境开发,下面学习下该方式
首先提下这种方式和sping加载配置文件的区别,pom文件通过profile配置的方式xml编译后里面的${}属性都是被替换掉实际的值了,不需要通过spring加载propertios来填充了。
<profiles>
<profile>
<id>releaseid>
<activation>
<activeByDefault>trueactiveByDefault>
activation>
<build>
<filters>
<filter>src/main/resources/profileconfig/cytjws-release.propertiesfilter>
filters>
build>
<properties>
<exclude.logfile>exclude.logfile>
properties>
profile>
<profile>
<id>devid>
<build>
<filters>
<filter>src/main/resources/profileconfig/cytjws-dev.propertiesfilter>
filters>
build>
profile>
profiles>
加完
标签是在 标签下的,通过标签指定web项目打包到classes下的资源,maven项目默认就是src/main/java,src/main/resources,配置文件按规范都是放到src/main/resources下。
所以在src/main/resources这个配置里增加了。这个属性非常关键,。
true
filtering:决定是否将resources目录下的文件中的${xxx}进行参数替换。这里的properties就是
<resources>
<resource>
<directory>src/main/javadirectory>
<excludes>
<exclude>**/*.javaexclude>
excludes>
resource>
<resource>
<directory>src/main/resourcesdirectory