在Mule中读取YAML文件

时间:2019-02-25 17:08:24

标签: mule

我无法读取由MuleSoft中的列表组成的YAML文件。

我将我的YAML文件设置为以下结构中的“全局元素”中的“配置”属性。

applications:
  - appId: "123456"
    appName: Application One
  - appId: "456789"
    appName: Application Two

没有列表时,我可以读取值。但是当我将其设置为列表时,MuleSoft会抛出此错误:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Failed to deploy artifact 'test', see below        +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
org.mule.runtime.deployment.model.api.DeploymentException: Failed to deploy artifact [test]
Caused by: org.mule.runtime.api.exception.MuleRuntimeException: org.mule.runtime.deployment.model.api.DeploymentInitException: ConfigurationPropertiesException: Configuration properties does not support type a list of complex types. Complex type keys are: appId,appName
Caused by: org.mule.runtime.deployment.model.api.DeploymentInitException: ConfigurationPropertiesException: Configuration properties does not support type a list of complex types. Complex type keys are: appId,appName
Caused by: org.mule.runtime.core.api.config.ConfigurationException: Configuration properties does not support type a list of complex types. Complex type keys are: appId,appName
Caused by: org.mule.runtime.config.internal.dsl.model.config.ConfigurationPropertiesException: Configuration properties does not support type a list of complex types. Complex type keys are: appId,appName

请帮助我:这不是使用YAML文件的正确方法吗?我需要更改格式吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

配置属性不支持作为复杂类型列表的类型。这些属性必须在后端转换为弹簧属性

您只能使用简单的列表:     应用范围:       -“ 123456”       -“ 456789”

但是一个简单的对象对于属性也同样适用:

applications:
  "123456":
      name: Application One
  "456789":
      name: Application Two

然后您可以通过appId动态查找,例如:

<set-variable variableName="appId" value="123456"  />
<logger level="INFO" message="#[p('applications.' ++ vars.appId ++ '.name')]" />