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

相关推荐
小马爱打代码5 小时前
Spring Boot:模块化实战 - 保持清晰架构
java·spring boot·架构
小坏讲微服务6 小时前
SpringBoot4.0整合knife4j 在线文档完整使用
java·spring cloud·在线文档·knife4j·文档·接口文档·swagger-ui
8***Z896 小时前
springboot 异步操作
java·spring boot·mybatis
i***13246 小时前
Spring BOOT 启动参数
java·spring boot·后端
坚持不懈的大白6 小时前
后端:SpringMVC
java
IT_Octopus6 小时前
(旧)Spring Securit 实现JWT token认证(多平台登录&部分鉴权)
java·后端·spring
kk哥88996 小时前
Spring详解
java·后端·spring
S***26756 小时前
Spring Cloud Gateway 整合Spring Security
java·后端·spring
Tao____7 小时前
开源物联网平台
java·物联网·mqtt·开源·设备对接
遇到困难睡大觉哈哈7 小时前
Harmony os——ArkTS 语言笔记(四):类、对象、接口和抽象类
java·笔记·spring·harmonyos·鸿蒙