【问题标题】:Accessing mule-app.properties in custom properties file located in src/main/resources on cloudhub在 cloudhub 上的 src/main/resources 中访问自定义属性文件中的 mule-app.properties
【发布时间】:2015-12-07 19:24:30
【问题描述】:

我有一个使用 mule apikit 构建的 mule 应用程序。 mule-app.properties 文件包含以下属性:

orig.db.url=jdbc:db2://mmrs001.nmd.net:1004/dudu:user=abc43;password=xxxx;

自定义属性文件 src/main/resources/dev.properties 包含以下属性:

db.url=${orig.db.url}

并且,mule 配置 xml 文件包含以下属性占位符:

<context:property-placeholder location="dev.properties"/>

现在,当我在本地部署它时,一切正常,我能够运行流程。但是,当我在 Cloudhub 上部署时,它给了我以下异常:

Invalid bean definition with name 'get:/total_amount:total_amount-db-config' defined in null: Could not resolve placeholder 'orig.db.url' in string value "jdbc:db2://mmrs001.nmd.net:1004/dudu:user=abc43;password=xxxx;"

我无法理解我在这里遗漏了什么?

【问题讨论】:

    标签: mule mule-studio cloudhub


    【解决方案1】:

    您是如何部署到 CloudHub 的?如果您使用 Anypoint Studio 中的部署工具,您可以选择在部署前设置属性。

    【讨论】:

      【解决方案2】:

      mule-app.properties 将被添加到系统属性而不是类路径属性中。我们不能从添加到类路径的属性文件中引用系统属性。我们需要将这些属性移动到类路径以在运行时解决这些问题。

      通过导入 mule-app.properties 来覆盖此行为的一种方法:

      <context:property-placeholder location="mule-app.properties,dev.properties”/>
      

      它告诉 spring 以相应的顺序加载属性。因此,首先加载 mule-app.properties,然后加载 dev.properties。

      但是,将 mule-app.properties 文件包含在类路径中并不是最佳做法。最好的方法是从 mule-app.properties 中删除 dev 属性并将其放入 dev.properties 中。

      【讨论】:

        【解决方案3】:

        默认情况下,当部署到 cloudhub 时,来自 mule-app.properties 的所有属性都应显示在属性选项卡中。您第一次部署时没有看到它们吗?

        【讨论】:

        • 是的!你说的对。 mule-app.properties 中的属性确实出现在属性选项卡中。但是,我在这里要做的是从 src/main/resources/custom.properties 中的 mule-app.properties 中引用一个属性。这可能吗?
        • @SumvedShami 你读过另一个答案吗?如果您通过 CloudHub 设置应用属性,您将完成您所需要的。
        • @granthbr 我肯定读过另一个答案。但是,我的问题是,如何从位于类路径中的属性文件中的 mule-app.properties 访问属性。
        猜你喜欢
        • 1970-01-01
        • 2017-10-03
        • 2015-03-22
        • 1970-01-01
        • 1970-01-01
        • 2020-07-20
        • 2014-06-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多