Mule动态属性文件引用

Mule动态属性文件引用,mule,mule-component,Mule,Mule Component,我们有一个流程,其中我们有如下所示的属性文件引用 "context:property-placeholder location="httpdemo.${country}.properties" 现在,我们希望在部署时用实际值替换${country}值 正如我们所知,实现它的一种方法是在ESB上将country的值设置为环境变量并进行部署。但我们不想这样做,原因如下: 我们为多个国家并行部署相同的代码库 环境属性只能在mule运行时启动期间设置,所以如果我将env变量设置为country=UK,

我们有一个流程,其中我们有如下所示的属性文件引用

"context:property-placeholder location="httpdemo.${country}.properties"
现在,我们希望在部署时用实际值替换
${country}

正如我们所知,实现它的一种方法是在ESB上将country的值设置为环境变量并进行部署。但我们不想这样做,原因如下:

  • 我们为多个国家并行部署相同的代码库

  • 环境属性只能在mule运行时启动期间设置,所以如果我将env变量设置为
    country=UK
    ,并且已经为UK部署了环境属性。稍后,我想再次部署,我需要通过设置
    country=MY
    重新启动ESB,我们不想这样做


  • 请告诉我是否有其他更好的方法

    您可以使用选项
    -M-Dmule.country=您的值


    您可能想了解一下

    我们遇到过类似的情况,我们需要让同一应用程序的多个版本并行运行。我们用于此的解决方案是将属性文件与构建打包在一起,而不使用动态元素(基于环境)。对于eg;在本例中,我们构建了httpdemo.usa.properties,并将其与应用程序一起打包。这对我们来说相当容易,因为我们使用Jenkins来管理构建和发布。发布构建时,我们引用Jenkins提供的配置文件,其中包含所有特定的“国家”相关属性。您甚至可以将此国家/地区作为参数传递给生成定义。使用自定义maven插件,我们用Jenkins属性文件中的新属性替换应用程序中的属性文件

    解决问题的另一个方法是遵循特定于您要使用的“国家”的应用程序命名约定,并使用Springbeans获取属性。对于eg

    <spring:beans>
        <spring:bean id="CountryProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
            <spring:property name="singleton" value="true"/>
            <spring:property name="location" value="${app.name}.properties"/>
        </spring:bean>
    </spring:beans>
    <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="5000" doc:name="HTTP Listener Configuration"/>
    <flow name="dynamic_propsFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
        <logger message="#[app.registry.CountryProperties['country.full.name']]" level="INFO" doc:name="Logger"/>
    </flow>
    

    ${app.name}提供已部署应用的名称。如果我的应用程序名为dynamic_props_usa,则它指的是dynamic_props_usa.properties。如果是dynamic_props_mexico,则表示dynamic_props_mexico.properties。希望这有帮助

    定义上下文属性占位符,使其在包中具有文件引用,并在运行时根据需要使用服务器覆盖该文件引用,如下所示

    <context:property-placeholder location="classpath:app-${mule.env}.properties,    file:${mule.config.path}/app-${mule.env}.properties" ignore-resource-not-found="true" ignore-unresolvable="true" />
    

    如果您为StackOverflow添加了引号,则您给出的示例包含的引号太多或太少。请用代码格式编辑并修复它。
    <context:property-placeholder location="classpath:app-${mule.env}.properties,    file:${mule.config.path}/app-${mule.env}.properties" ignore-resource-not-found="true" ignore-unresolvable="true" />