# 多环境配置与应用

# 多环境开发

image_2023-03-07-15-42-01

  • maven 提供配置多种环境的设定,帮助开发者,使用过程中快速切换环境
  1. 配置多种环境的配置文件信息
<profiles>
        <profile>
            <id>env_1</id>
            <properties>
                <url>jdbc:mysql://127.1.1.1:3306/ssm_db?characterEncoding=utf-8&amp;serverTimezone=UTC</url>
            </properties>
            <!--                设定是否为默认启动环境 -->
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>env_2</id>
            <properties>
                <url>jdbc:mysql://127.2.2.2:3306/ssm_db?characterEncoding=utf-8&amp;serverTimezone=UTC</url>
            </properties>
        </profile>
        <profile>
            <id>env_3</id>
            <properties>
                <url>jdbc:mysql://127.3.3.3:3306/ssm_db?characterEncoding=utf-8&amp;serverTimezone=UTC</url>
            </properties>
        </profile>
    </profiles>
  1. 在 profile 标签中使用 <activation><activeByDefault>true</activeByDefault></activation > 标签指定使用哪个配置信息

# 使用 mvn 指令构建指定环境

  1. 还可以使用 mvn 指令来指定运行哪个配置信息

mvn install -P env_1 -P 为指定 运行 Install env_1 中的配置信息

image_2023-03-07-16-45-19

查看 jar 包中的 druid 配置文件的 url 信息

image_2023-03-07-16-45-50