访问 cloudhub 上 src/main/resources 中自定义属性文件中的 mule-app.properties

Accessing mule-app.properties in custom properties file located in src/main/resources on cloudhub

我有一个使用 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;"

我不明白我在这里错过了什么?

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

默认情况下,当部署到 cloudhub 时,mule-app.properties 中的所有属性都应该出现在属性选项卡中。第一次部署的时候没看到吗?

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.