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

相关推荐
淘源码d4 分钟前
基于Spring Boot + Vue的诊所管理系统(源码)全栈开发指南
java·vue.js·spring boot·后端·源码·门诊系统·诊所系统
李少兄5 分钟前
IntelliJ IDEA 中撤销 Commit
java·elasticsearch·intellij-idea
iPadiPhone7 分钟前
Java 反射机制底层原理、面试陷阱与实战指南
java·开发语言·后端·面试
iPadiPhone12 分钟前
Java SPI 机制全链路深度解析与面试通关指南
java·后端·面试
问道飞鱼14 分钟前
【大模型学习】LangChain 入门指南:基本概念、核心功能与简单示例
java·学习·langchain
blackorbird24 分钟前
Palantir的战争AI:藏在美军Maven系统里的Claude大模型
java·大数据·人工智能·maven
左左右右左右摇晃33 分钟前
Java String 类笔记
java
on the way 1231 小时前
day10 - Spring 之配置类源码解析
java·后端·spring
行者-全栈开发1 小时前
JDK 17 + Spring Boot 3.5.8:企业级开发技术栈全景
java·开发语言·spring boot·系统架构·技术栈·系统架构全景分析·springboot技术栈
WHS-_-20221 小时前
mCore: Achieving Sub-millisecond Scheduling for 5G MU-MIMO Systems
java·算法·5g