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表达式

    以上。

           

  • 相关阅读:
    React 学习笔记
    需要充实自己的课外东西
    近期计划
    测试TinyMCE编辑器
    我的第二篇博客园随笔
    博客已搬运至https://wz71014q.github.io
    关于HTTPS通信机制的笔记
    JS中数组的一些笔记
    Three学习之曲线
    Three入门学习笔记整理
  • 原文地址:https://www.cnblogs.com/sinsonglew/p/15704115.html
Copyright © 2011-2022 走看看