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

相关推荐
老骥伏枥~12 分钟前
基于Spring Boot + Vue.js的图书管理系统
vue.js·spring boot·后端
叙白冲冲21 分钟前
JAVA中栈的使用
java·开发语言
银发控、23 分钟前
Builder Pattern
spring boot·spring·建造者模式
sanshizhang26 分钟前
jspringboot 调用腾讯短信
java·短信验证码
Tong Z29 分钟前
Spring Boot 请求处理链路
java·spring boot·后端
rabbitlzx29 分钟前
《Async in C# 5.0》第十四章 深入探讨编译器对于async的转换
java·开发语言·c#·异步·asynchronous
LSL666_31 分钟前
3 Redis 的 Java 客户端
java·数据库·redis
虫师c32 分钟前
Spring Boot自动配置黑魔法:手写Starter实现原理深度解析
java·spring boot·后端·自动配置·starter
code袁35 分钟前
基于Springboot+Vue的家教小程序的设计与实现
vue.js·spring boot·小程序·vue·家教小程序
范什么特西40 分钟前
狂神---死锁
java·前端·javascript