Apache camel 使用Spring DSL的Camel custom@Converter存在问题
我只是想学习自定义转换器,遇到了问题。非常感谢您的帮助。驼峰版本2.17和JBoss Fuse 6.3Apache camel 使用Spring DSL的Camel custom@Converter存在问题,apache-camel,spring-dsl,Apache Camel,Spring Dsl,我只是想学习自定义转换器,遇到了问题。非常感谢您的帮助。驼峰版本2.17和JBoss Fuse 6.3 @Converter public class MyConvertor{ public MyConvertor(){} @Converter public static String convertTo(Exchange exchange) {} } 在我的春季DSL中 <convertBodyTo charset="UTF-8" id="_convert
@Converter
public class MyConvertor{
public MyConvertor(){}
@Converter
public static String convertTo(Exchange exchange) {}
}
在我的春季DSL中
<convertBodyTo charset="UTF-8" id="_convertBodyTo1" type="com.x.convertor.MyConvertor"/>
错误消息:
org.apache.camel.InvalidPayloadException: No body available of type: com.x.convertor.MyConvertor but has value: GenericFile[output.txt] of type: org.apache.camel.component.file.GenericFile on: output.txt. Caused by: No type converter available to convert from type:
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.apache.camel.component.file.GenericFile to the required type: com.x.convertor.MyConvertor
有几个错误。
type
属性应该是您的目标类型(转换后需要的类型)
见如果要读取CSV文件的内容以将其转换为POJO,请使用组件。不走运。更新更改如下。请您帮助转换器公共类MyConvertor{Converter public JSONObject convertTo(GenericFile文件)抛出JSONException,IOException{return JSONObject;}}
org.apache.camel.InvalidPayloadException: No body available of type: com.x.convertor.MyConvertor but has value: GenericFile[output.txt] of type: org.apache.camel.component.file.GenericFile on: output.txt. Caused by: No type converter available to convert from type:
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.apache.camel.component.file.GenericFile to the required type: com.x.convertor.MyConvertor
<convertBodyTo charset="UTF-8" id="_convertBodyTo1" type="java.lang.String"/>
@Converter
public class MyConvertor{
public MyConvertor(){}
@Converter
public static String convertTo(GenericFile body, Exchange exchange) {
// The exchange parameter is optional
}
}