zoukankan      html  css  js  c++  java
  • Spring启动时指定properties文件B 依赖于properties文件A的配置项x (Spring multiple properties files picking one by config item in parent properties file)

     

    问题描述

            在一个多环境的项目中,代码里可能会存在N多properties配置文件,但是在运行时仅希望其中一份生效;举个例子,test环境还细分项目test环境:aws-test, azure-test,common-test。运行时为了减少配置项,仅会指定根配置文件root.properties,希望在根配置文件内指定具体项目的env_xxx_biz.properites。

    如何解决

        <util:properties id="rootConf" location="file:${root_conf:conf/root.properties}" />
        <util:properties id="bizConf" location="#{rootConf.getProperty('biz.config.location')?:'/WEB-INF/biz-${spring.profiles.active}.properties'}"/>

           如上示例代码,rootConf 是spring applicationContext.xml里配置的 root properties 文件,其内容可能会有一个key为biz.config.location的配置项,如存在以该key指向的properties文件为具体的bizConf文件,如没有该配置项,会以默认的biz properties 文件进行实例化。bizConf的配置使用语法为spring spel表达式

    以上。

           

  • 相关阅读:
    LeetCode周赛#209
    CodeBlocks相关配置
    LeetCode双周赛#36
    LCCUP 2020 秋季编程大赛 补题
    while和do while区别
    完全背包--piggy-bank
    数组定义在哪里???重要!!!
    01背包---点菜问题
    java源程序命名规则
    hdu1159-----最长公共子序列LCS
  • 原文地址:https://www.cnblogs.com/sinsonglew/p/15704115.html
Copyright © 2011-2022 走看看