springCloud配置maven打包时使用profile激活当前运行环境并且打包时使用案例
<project><!-- ... 其他配置 ... --><!-- 第1步:定义环境Profile --><profiles><!-- 开发环境 (默认激活) --><profile><id>dev</id><properties><!-- 此处的 profileActive 是自定义属性,值会被注入到YAML --><profileActive>dev</profileActive></properties><activation><activeByDefault>true</activeByDefault> <!-- 默认激活 --></activation></profile><!-- 生产环境 --><profile><id>prod</id><properties><profileActive>prod</profileActive></properties></profile><!-- 可根据需要添加更多环境,如test --></profiles><!-- 第2步:配置资源过滤 --><build><resources><resource><directory>src/main/resources</directory><filtering>true</filtering> <!-- 开启过滤 --><includes><!-- 明确指定需要被过滤(替换占位符)的文件 --><include>application.yml</include><!-- 如果需要,也可以包含其他配置文件 --></includes></resource><!-- 可选:处理其他不包含占位符的静态资源文件 --><resource><directory>src/main/resources</directory><filtering>false</filtering> <!-- 关闭过滤 --><excludes><exclude>application.yml</exclude></excludes></resource></resources><!-- ... 其他插件配置 ... --></build>
</project>