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

SpringBoot的yml多环境配置

创建多个配置文件

yaml 复制代码
application.yml      #主配置文件
application-dev.yml  #开发环境的配置
application-test.yml #测试环境的配置

在application.yml中添加多环境配置属性

yaml 复制代码
spring:
  profiles:
    active: @profiles.active@

项目启动可能不会识别@,在pom.xml中设置filtering为true

xml 复制代码
<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering> 
            <includes>
                <include>**/*.*</include>
            </includes>
        </resource>
    </resources>
</build>

在pom.xml中指定使用的配置

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

相关推荐
kk哥889918 小时前
分享一些学习JavaSE的经验和技巧
java·开发语言
栈与堆18 小时前
LeetCode 21 - 合并两个有序链表
java·数据结构·python·算法·leetcode·链表·rust
lagrahhn18 小时前
Java的RoundingMode舍入模式
java·开发语言·金融
鸽鸽程序猿18 小时前
【JavaEE】【SpringCloud】注册中心_nacos
java·spring cloud·java-ee
云上凯歌18 小时前
01 GB28181协议基础理解
java·开发语言
Coder_Boy_19 小时前
基于SpringAI的在线考试系统-考试系统DDD(领域驱动设计)实现步骤详解
java·数据库·人工智能·spring boot
毕设源码-钟学长19 小时前
【开题答辩全过程】以 基于Java的运动器材销售网站为例,包含答辩的问题和答案
java·开发语言
workflower19 小时前
软件需求规约的质量属性
java·开发语言·数据库·测试用例·需求分析·结对编程
TracyCoder12319 小时前
Java String:从内存模型到不可变设计
java·算法·string
想用offer打牌19 小时前
Spring AI Alibaba与 Agent Scope到底选哪个?
java·人工智能·spring