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

相关推荐
Holen&&Beer5 分钟前
Spring-Profile与部署说明
java·后端·spring
棉花糖超人5 分钟前
【操作系统】三、线程
java·开发语言·操作系统
liuyao_xianhui12 分钟前
优选算法_判断字符是否唯一_C++
java·开发语言·数据结构·c++·算法·链表
代码雕刻家15 分钟前
3.4.Maven-idea集成-导入Maven项目
java·maven·intellij-idea
2301_8035545220 分钟前
c++中的CAS是什么
java·开发语言·c++
何中应26 分钟前
Easy-Es整合
大数据·spring boot·elasticsearch·搜索引擎
java1234_小锋26 分钟前
Java高频面试题:RabbitMQ中有哪几种交换机类型?
java·rabbitmq·java-rabbitmq
翘着二郎腿的程序猿30 分钟前
SpringBoot集成@Slf4j注解:优雅输出日志,告别手动new Logger
java·spring boot·intellij-idea
wyt53142931 分钟前
新手如何快速搭建一个Springboot项目
java·spring boot·后端
jinanmichael32 分钟前
【SpringBoot】日志文件
java·spring boot·spring