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.启动之后查看引入之后的文件

已经是配置之后的内容了

相关推荐
彦为君9 小时前
JavaSE-11-ByteBuffer(NIO核心组件)
java·开发语言·前端·数据库·后端·spring·nio
Kiling_07049 小时前
面向对象和集合编程题 ( 二 )
java·开发语言·数据结构·算法
菜鸡儿齐9 小时前
Future接口学习
java·服务器·开发语言
过期动态9 小时前
【LeetCode 热题 100】两数之和— 暴力法与哈希表法详解
java·数据结构·算法·leetcode·散列表
Refrain_zc9 小时前
Android开发在线音频播放器之章节三核心PlayerService
java
日月云棠9 小时前
17 Dubbo 2.7 集群容错策略源码解析
java·后端
Refrain_zc9 小时前
Android开发纯按键文件浏览器
java
monkeyhlj9 小时前
Harness理解学习
java·人工智能·python·学习·ai编程
西凉的悲伤10 小时前
SpringBoot WebClient 介绍
java·spring boot·后端·webclient