springboot 属性文件中使用 pom文件 profile 参数


springboot可以从 pom 文件中获取参数,这样可以 在打包时,根据环境(开发、测试)指定参数,就不用再 运行jar 包再指定参数了。

最常用的就是,激活配置文件参数:spring.profiles.active=activeProperty

用法:
1)springboot 配置文件

#propertis文件方式
spring.profiles.active=@activatedProperties@


#yaml文件方式
spring:
   profiles:
      active: @activatedProperties@

2)pom文件

 <profiles>
        <profile>
            <!-- 开发 -->
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <activatedProperties>dev</activatedProperties>
            </properties>
        </profile>
        <profile>
            <!-- 测试 -->
            <id>test</id>
            <properties>
                <activatedProperties>test</activatedProperties>
            </properties>
        </profile>
        <profile>
            <!-- 生产 -->
            <id>prod</id>
            <properties>
                <activatedProperties>prod</activatedProperties>
            </properties>
        </profile>
  </profiles>

  1. 打包
# -P 后的 参数是 profile 中的 id。 默认是 activeByDefault 为 true的 dev
# 测试打包
# springboot 配置文件 application-test.properoties 或 application-test.yaml 生效
mvn clean package -P  test

# 生产打包
#  springboot 配置文件 application-prod.properoties 或 application-prod.yaml 生效
mvn clean package -P prod

以上演示了 pom 自定义参数 activatedProperties ,被 springboot读取的实例。

https://www.cnblogs.com/zeng1994/p/06917ed3b98677fa7a1b0f74de16c3be.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM