Nat*_*lus 3 mule anypoint-studio dataweave
我有一个非常简单的hashmap有效负载转换为application/json.我在其他流程中通过拖动dataweave组件并编写映射表达式来完成此操作.
现在由于某种原因,我收到以下错误:
与元素类型"dw:transform-message"相关联的属性"metadata:id"的前缀"metadata"未绑定.
当我看到xml时,我看到我的新dataweave组件没有metadata:id属性,但我使用的另一个dataweave组件确实有一个metadata:id属性.
使用DataWeave组件时,需要声明xml命名空间.如果您使用的是Studio设计器,则只要将组件拖放到配置中,Studio就会添加相关的命名空间.
因此,当您拖放dataweave组件时,studio会将以下命名空间和架构位置添加到配置中 -
xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
Run Code Online (Sandbox Code Playgroud)
在Mule中,您可以为每个组件定义MetaData,这有助于在设计时查看数据结构.所有这些元数据定义都存储在{project_home}\catalog文件夹下,文件名看起来像UUID.然后使用metadata:id属性将这些文件名添加到组件定义中.即使一个组件(不必将DW作为元数据作为所有组件共有的特征),您也需要元数据命名空间.
<dw:transform-message metadata:id="262e6569-8f38-4e0b-a61d-15550870101e" doc:name="Transform Message">
如果您从Studio设计器添加元数据,则Studio应自动添加以下命名空间和架构位置.如果你手动添加它或从一个xml复制粘贴到没有它的另一个xml那么你需要自己添加它 -
xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata"
使用Dataweave和元数据的示例配置如下所示 -
<mule xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
Run Code Online (Sandbox Code Playgroud)