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 分钟前
04-Java JDK, JRE和JVM
java·开发语言·jvm
camellias_6 小时前
【无标题】
java·tomcat
咸鱼2.07 小时前
【java入门到放弃】需要背诵
java·开发语言
椰猫子7 小时前
Java:异常(exception)
java·开发语言
win x8 小时前
Redis 使用~如何在Java中连接使用redis
java·数据库·redis
星晨雪海8 小时前
基于 @Resource 的支付 Service 多实现类完整示例
java·开发语言
阿维的博客日记8 小时前
什么是逃逸分析
java·juc
Ricky_Theseus9 小时前
C++右值引用
java·开发语言·c++
Rick19939 小时前
Java内存参数解析
java·开发语言·jvm
我是大猴子9 小时前
Spring代理类为何依赖注入失效?
java·后端·spring