SpringBoot+Maven多环境配置模式

我这里有两个配置文件

然后在最外层的父级POM文件里面把这个两个配置文件写上

复制代码
<profiles>
        <profile>
            <id>druid</id>
            <properties>
                <spring.profiles.active>druid</spring.profiles.active>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>

        <profile>
            <id>test</id>
            <properties>
                <spring.profiles.active>test</spring.profiles.active>
            </properties>
        </profile>
    </profiles>

右上角Maven里面就出现了可选择的配置

然后在主配置里面选择获取Maven使用的配置

复制代码
spring.profiles.active=@spring.profiles.active@

然后正常启动项目或打包就行了。

下面是爬坑过程中遇到的两个坑

1、按别人教程来,项目能打包,但是ide里面死活启动不了,最后发现是把profile配置里面的build删掉就行

2、解决问题1后,右上角maven来回切换配置后,ide再启动结果发现又启动不起来,这时候先点击清除,再启动就行了

相关推荐
程序员清风8 小时前
程序员兼职必看:靠谱软件外包平台挑选指南与避坑清单!
java·后端·面试
皮皮林5519 小时前
利用闲置 Mac 从零部署 OpenClaw 教程 !
java
洋洋技术笔记14 小时前
Spring Boot配置管理最佳实践
spring boot
华仔啊14 小时前
挖到了 1 个 Java 小特性:var,用完就回不去了
java·后端
SimonKing15 小时前
SpringBoot整合秘笈:让Mybatis用上Calcite,实现统一SQL查询
java·后端·程序员
日月云棠1 天前
各版本JDK对比:JDK 25 特性详解
java
用户8307196840821 天前
Spring Boot 项目中日期处理的最佳实践
java·spring boot
JavaGuide1 天前
Claude Opus 4.6 真的用不起了!我换成了国产 M2.5,实测真香!!
java·spring·ai·claude code
IT探险家1 天前
Java 基本数据类型:8 种原始类型 + 数组 + 6 个新手必踩的坑
java
花花无缺1 天前
搞懂new 关键字(构造函数)和 .builder() 模式(建造者模式)创建对象
java