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

已经是配置之后的内容了

相关推荐
weixin_30777913几秒前
Jenkins Branch API插件详解:多分支项目管理的核心引擎
java·运维·开发语言·架构·jenkins
milanyangbo6 分钟前
从硬盘I/O到网络传输:Kafka与RocketMQ读写模型及零拷贝技术深度对比
java·网络·分布式·架构·kafka·rocketmq
小股虫6 分钟前
消息中间件关键技术、设计原理与实现架构总纲
java·开发语言·架构
风萧萧19997 分钟前
Java:PPT转图片
java·python·powerpoint
洲星河ZXH8 分钟前
Java,日期时间API
java·开发语言·python
老华带你飞15 分钟前
动物救助|流浪狗救助|基于Springboot+vue的流浪狗救助平台设计与实现(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·流浪动物救助平台
Hernon17 分钟前
微服务架构设计:从零打造互联网车贷系统 —— 业务背景与架构蓝图
java·微服务·架构·微服务架构设计
9523619 分钟前
二叉平衡树
java·数据结构·学习·算法
Vic1010122 分钟前
Java正则表达式性能优化指南:编译开销、类加载与线程安全深度解析
java·性能优化·正则表达式
小二·28 分钟前
Spring框架入门:代理模式详解
java·spring·代理模式