关于maven中profiles多环境的配置

来源:互联网 发布:网络爬虫技术 java 编辑:程序博客网 时间:2024/05/21 19:32

问题

  • 在传统项目中需要手动修改配置来进行打包,而我们是程序员,是以不可配置为耻,可配置为荣的。

步骤

1,在pom文件中添加一个环境的配置

<profiles>        <profile>            <!-- 本地开发环境 -->            <id>local</id>            <activation>                <activeByDefault>true</activeByDefault>            </activation>            <properties>                <profiles.active>local</profiles.active>                <username>zhb</username>                <password>123456</password>            </properties>        </profile>        <profile>            <!-- 生产环境 -->            <id>pro</id>            <properties>                <profiles.active>pro</profiles.active>                <username>zhb</username>                <password>123456</password>            </properties>        </profile>    </profiles>

2,需要在build中指定哪里可以取出这些配置

<build>        <finalName>study-pom</finalName>        <resources>            <resource>                <directory>src/main/resources</directory>                <includes>                    <include>**/*.*</include>                </includes>                <filtering>true</filtering>            </resource>        </resources>    </build>

3,在指定的位置取到这些配置

这里写图片描述

在config.properties文件取出动态配置的方法

username=${username}password=${password}profiles.active=${profiles.active}
原创粉丝点击