美文网首页
maven profile

maven profile

作者: 田文健 | 来源:发表于2019-12-06 09:11 被阅读0次

profile 能让maven项目在不同的环境下加载不同的配置,在pom文件中加入(如果是多模块项目,加在父POM中即可)

<profiles>
        <profile>
            <id>dev</id>
            <properties>
                <profileActive>dev</profileActive>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <profileActive>test</profileActive>
            </properties>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <profileActive>prod</profileActive>
            </properties>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
        </profile>
    </profiles>

现在在resources目录下创建多个配置文件:


image.png

在resource标签内,可以指定加载的配置文件:

<resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>application-${profileActive}.properties</include>
                </includes>
                <excludes>
                </excludes>
            </resource>

另外代码里,也可指定要加载的配置:

@PropertySource(value = {"classpath:service.properties","classpath:service-${spring.profiles.active}.properties"})

相关文章

  • SpringBoot之条件注解

    背景 之前写过关于Spring和Maven的profile的区别 maven profile VS spring ...

  • maven---灵活构建(一)

    包含内容 maven属性 构建环境的差异 资源过滤 Maven Profile Web资源过滤 在profile中...

  • maven profile多环境配置

    使用maven profile实现多环境配置(代码) maven profile 实现多环境可移植构建 在开发过程...

  • centos7 安装 maven3.5

    下载maven 配置环境变量 vi /etc/profile source /etc/profile

  • Maven - Profile

    什么是profile profile是在maven xml中配置的,由 包围的一块配置 profile的作用 通...

  • Maven - profile

    版权所有,未经授权,禁止转载 章节 Maven – 简介 Maven – 工作原理 Maven – Reposit...

  • maven profile

    profile 能让maven项目在不同的环境下加载不同的配置,在pom文件中加入(如果是多模块项目,加在父POM...

  • 【转载】Maven管理SpringBoot Profile

    Maven管理SpringBoot Profile 1. Spring Profile Spring可使用Prof...

  • Profile

    帮助命令 查看项目中哪些profile被激活了 列出当前所有profile maven属性 maven有6类属性,...

  • 2020-03-19 springboot 打包运行

    打包 指定profile mvn clean package -Pbeta 指定profile以maven命令的方...

网友评论

      本文标题:maven profile

      本文链接:https://www.haomeiwen.com/subject/pjssgctx.html