IDEA中SpringBoot项目的yml多环境配置方式
作者:黎明晓月
这篇文章主要介绍了IDEA中SpringBoot项目的yml多环境配置,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧
SpringBoot的yml多环境配置
创建多个配置文件
application.yml #主配置文件 application-dev.yml #开发环境的配置 application-test.yml #测试环境的配置
在application.yml中添加多环境配置属性
spring:
profiles:
active: @profiles.active@项目启动可能不会识别@,在pom.xml中设置filtering为true
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
</build>在pom.xml中指定使用的配置
<profiles>
<profile>
<id>dev</id>
<activation>
<!-- 默认激活-->
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profiles.active>dev</profiles.active>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<profiles.active>test</profiles.active>
</properties>
</profile>
</profiles>到此即为配置完毕,在maven->profiles下勾选动态激活需要使用的配置,想使用哪个配置勾选即可,其余的配置勾除,最后启动项目使用的配置就是勾选的配置文件

参考文章:https://blog.csdn.net/github_36665118/article/details/130555496
到此这篇关于IDEA中SpringBoot项目的yml多环境配置的文章就介绍到这了,更多相关idea springboot多环境配置内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
