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

已经是配置之后的内容了

相关推荐
qq_5470261792 小时前
Flowable 工作流引擎
java·服务器·前端
鼓掌MVP3 小时前
Java框架的发展历程体现了软件工程思想的持续进化
java·spring·架构
编程爱好者熊浪3 小时前
两次连接池泄露的BUG
java·数据库
lllsure3 小时前
【Spring Cloud】Spring Cloud Config
java·spring·spring cloud
鬼火儿4 小时前
SpringBoot】Spring Boot 项目的打包配置
java·后端
NON-JUDGMENTAL4 小时前
Tomcat 新手避坑指南:环境配置 + 启动问题 + 乱码解决全流程
java·tomcat
chxii5 小时前
Maven 详解(上)
java·maven
李少兄5 小时前
IntelliJ IDEA 远程调试(Remote Debugging)教程
java·ide·intellij-idea
Kuo-Teng5 小时前
Leetcode438. 找到字符串中所有字母异位词
java·算法·leetcode
毕设小屋vx ylw2824265 小时前
Java开发、Java Web应用、前端技术及Vue项目
java·前端·vue.js