idea pom profiles 配置的使用

如题所述

第1个回答  2022-07-27
多配置文档的使用

Maven 中有一个概念叫做:profile,它的诞生主要是为了解决不同环境所需的不同变量、配置等问题。

有了 profile,可以根据激活的条件,启动不同条件下的配置信息。

profile 是可以有多个的,也可以同时激活多个 profile,方便自由组合。

<build>

<plugins>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

</plugin>

</plugins>

<resources>

<resource>

<directory>src/main/resources</directory>

<filtering>true</filtering>

<excludes>

<exclude>application.properties</exclude>

<exclude>application-dev.properties</exclude>

<exclude>application-local.properties</exclude>

</excludes>

</resource>

<resource>

<directory>src/main/resources</directory>

<filtering>true</filtering>

<includes>

<include>application-${profiles.active}.properties</include>

            </includes>

</resource>

</resources>

</build>

<profiles>

<profile>

<!-- 开发环境 -->

        <id>dev</id>

<!--这三行不管用-->

        <activation>

<activeByDefault>true</activeByDefault>

</activation>

</profile>

<profile>

<!-- 生产环境 -->

        <id>prod</id>

<properties>

<profiles.active>prod</profiles.active>

</properties>

</profile>

</profiles>

并在application.properties中加载

spring.profiles.active =@profiles.active@

只需在右侧的profiles的选项打对应的√就行。

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网