IDEA中SpringBoot项目的yml多环境配置

编程入门 行业动态 更新时间:2024-10-20 11:41:19

IDEA中SpringBoot项目的yml多<a href=https://www.elefans.com/category/jswz/34/1771403.html style=环境配置"/>

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下勾选动态激活需要使用的配置,想使用哪个配置勾选即可,其余的配置勾除,最后启动项目使用的配置就是勾选的配置文件

参考文章:

更多推荐

IDEA中SpringBoot项目的yml多环境配置

本文发布于:2023-12-08 00:49:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1672141.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:环境   项目   IDEA   SpringBoot   yml

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!