maven profiles 配置

1.pom.xml中的文件配置

复制代码
<profiles>
        <profile> <!-- 开发/本地 默认激活 -->
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation> <!--默认启用的是dev环境配置-->
            <properties>
                <environment>dev</environment>
            </properties>
        </profile>
        <profile>    <!-- 测试环境 -->
            <id>test</id>
            <properties>
                <environment>test</environment>
            </properties>
        </profile>
        <profile>
            <id>prod</id> <!-- 生产环境 -->
            <properties>
                <environment>prod</environment>
            </properties>
        </profile>

    </profiles>

2.增加filter

复制代码
<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    ...
</build>

3.在idea 中的 profile 中指定配置的变量"

4.在properties 文件中配置引入的变量

5.执行 mvn clean compile

6.在 class 文件中查看打包后的内容如下:

7.启动之后查看引入之后的文件

已经是配置之后的内容了

相关推荐
karry_k10 小时前
MyBatis批量insert-select踩坑:useGeneratedKeys=true 可能让PostgreSQL返回大量插入结果
java·后端
karry_k10 小时前
PostgreSQL 在 MyBatis 中执行正常 SQL 失效:一次 DELETE USING 踩坑记录
java·后端
SamDeepThinking14 小时前
从源码到代码:MyBatis-Flex 与 MyBatis-Plus 的逐项对比
java·后端·程序员
她的男孩16 小时前
Spring Boot 接 Flowable 工作流:用 3 个注解搭一个请假审批流程
java·后端·架构
荣码18 小时前
LLM结构化输出:让AI返回JSON而不是废话,我踩了4个坑
java·python
plainGeekDev20 小时前
Gson → kotlinx.serialization
android·java·kotlin
小bo波1 天前
Java Swing 图形用户界面实验 —— 从算术练习到游戏开发的完整实践
java·课程设计·gui·游戏开发·扫雷·swing
咖啡八杯1 天前
GoF设计模式——备忘录模式
java·后端·spring·设计模式