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

已经是配置之后的内容了

相关推荐
WIN赢9 分钟前
【抽象思想-从复杂中抽离简单、收敛的口子】
java·前端·javascript
captain37613 分钟前
多线程单例模式
java·单例模式·java-ee
xiaotianyuanma39 分钟前
【计算机毕业设计】基于Spring Boot的体育馆预约系统的设计与实现
java·spring boot·课程设计
何以解忧,唯有..40 分钟前
MySQL 索引分类与底层原理深度剖析
java
水无痕simon1 小时前
6、六大工作模式-2
java·rabbitmq
2601_963870211 小时前
【计算机毕业设计】基于Spring Boot的非遗文创产品交易平台的设计与实现
java·spring boot·后端
lv__pf2 小时前
Spring之AOP底层源码解析(下)【TL spring14】
java·后端·spring
水无痕simon2 小时前
5、六大工作模式-1
java
KhalilRuan2 小时前
UnityCsReference——笔记
java·开发语言·笔记
何以解忧,唯有..3 小时前
SpringBoot 中 @Transactional 注解失效的 8 种常见场景与解决方案
java