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

相关推荐
shepherd1261 天前
破局延时任务(上):为什么选择Spring Boot + DelayQueue来自研分布式延时队列组件?
java·spring boot·后端·1024程序员节
机灵猫1 天前
微服务中的服务熔断、降级与限流
java·数据库·微服务
雨夜之寂1 天前
第一章-第三节-Java开发环境配置
java·后端
郑清1 天前
Spring AI Alibaba 10分钟快速入门
java·人工智能·后端·ai·1024程序员节·springaialibaba
zl9798991 天前
SpringBoot-Web开发之数据响应
java·spring boot·后端
旷野说1 天前
Spring Boot 1.x、2.x 3.x区别汇总
java·spring·tomcat·1024程序员节
也许是_1 天前
Spring Boot 3.X推荐Micrometer Tracing 分布式链路追踪
spring boot·分布式·后端
没有bug.的程序员1 天前
Spring Boot 起步:自动装配的魔法
java·开发语言·spring boot·后端·spring·1024程序员节
Hero | 柒1 天前
设计模式之建造者模式
java·设计模式·1024程序员节
CodeLongBear1 天前
帝可得智能售货机系统实战Day1:从环境搭建到区域管理功能落地 (1)
java·1024程序员节·ai + 若依框架