【发布时间】:2015-12-14 14:30:22
【问题描述】:
我正在考虑实现一个集成场景,我需要执行从源到目标的动态映射,问题是映射应该是相当可配置的,并且不能链接到固定值。
我使用 Camel 作为集成框架并导入文件(可以有不同的数据结构,但我们假设它是 CSV 文件)然后我需要将文件中的数据映射到内部格式。我正在研究使用 Dozer 和 XML 映射配置来执行此映射。
所以我想做的是加载文件,解组 CSV,然后拆分文件,接下来我想将骆驼体内的 HashMap(由 CSV 解组生成)映射到另一个 hashMap 但更改值的键。
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://camel.apache.org/schema/springhttp://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="Debug" class="com.mycompany.camel.spring.DebugProcessor" />
<bean id="dozerConverterLoader"
class="org.apache.camel.converter.dozer.DozerTypeConverterLoader" />
<bean id="DynamicMapper" class="org.dozer.DozerBeanMapper">
<property name="mappingFiles">
<list>
<value>Mapping.xml</value>
</list>
</property>
</bean>
<camelContext trace="false"
xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file:src?fileName=sample_data.csv&noop=true" />
<unmarshal>
<csv delimiter="," skipHeaderRecord="true" useMaps="true" />
</unmarshal>
<split>
<simple>${body}</simple>
<bean ref="Debug" />
<bean ref="DynamicMapper" />
<bean ref="Debug" />
</split>
</route>
</camelContext>
映射文件如下(纯作为示例,这显然会扩展更多字段映射)
<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns="http://dozer.sourceforge.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://dozer.sourceforge.net http://dozer.sourceforge.net/schema/beanmapping.xsd">
<mapping>
<class-a>java.util.HashMap</class-a>
<class-b>java.util.HashMap</class-b>
<field>
<a key="overtimehours">this</a>
<b key="OVT_HRS">TargetMap</b>
</field>
</mapping>
</mappings>
但是,当我执行骆驼路线时,我不断收到异常“org.dozer.MappingException:Destination class must not be null”
我做错了什么?也欢迎任何其他建议来实现动态映射功能。
【问题讨论】:
-
您需要显示动态映射器的代码,因为这是失败的推土机代码。另请阅读推土机文档该错误在推土机土地中的含义。
标签: apache-camel dozer