开发者

IDEA中SpringBoot项目的yml多环境配置方式

开发者 https://www.devze.com 2023-11-20 10:43 出处:网络 作者: 黎明晓月
SpringBoot的yml多环境配置 创建多个配置文件 application.yml#主配置文件 application-dev.yml#开发环境的配置

SpringBoot的yml多环境配置

创建多个配置文件

application.yml      #主配置文件
application-dev.yml  #开发环境的配置
application-test.yml #测试环境的配置

在application.yml中添加多环境配置属性

spring:
  profiles:
    active: @profiles.active@

项目启动可能不会识别@,在pom.XML中设置filtering为trpythonue

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering> 
            <includes>
                <include>**/*.*javascript</include>
            </includes>
        </resource>
   javascript </resources>
</build>

在pom.xml中指定使用的配置

   <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <!--  默认激活-->
      www.devze.com          <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下勾选动态激活需要使用的配置,想使用哪个配置勾选即可,其余的配置勾除,最后启动项目使用的配置就是勾选的配置文件

IDEA中SpringBoot项目的yml多环境配置方式

参考文章:https://blog.csdn.net/github_36665118/article/details/130555496

到此这篇关于IDEA中SpringBoot项目的yml多环境配置的文章就介绍到这了,更多相关idea springboot多环境配置内容请搜索编程客栈(www.devze.com)以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程客栈(www.devze.com)编程

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号