相关疑难解决方法(0)

org.apache.camel.NoTypeConversionAvailableException:没有可用于转换类型的类型转换器:

我首先有多部分文件,我想将其发送到骆驼管道并使用原始名称保存该文件。

我的代码:

@Autowired
ProducerTemplate producerTemplate;
...
      producerTemplate.sendBody("seda:rest_upload", multipartFile);
Run Code Online (Sandbox Code Playgroud)

在另一边我有:

from("seda:rest_upload").convertBodyTo(File.class).to("file://rest_files");

我还尝试注册转换器:

@Converter
public class MultiPartFileToFileConvertor {
    @Converter
    public static File toFile(MultipartFile multipartFile) throws IOException {
        File convFile = new File(multipartFile.getOriginalFilename());
        multipartFile.transferTo(convFile);
        return convFile;
    }
}
Run Code Online (Sandbox Code Playgroud)

当我执行代码时,我看到以下堆栈跟踪:

Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
[route2            ] [route2            ] [seda://rest_upload                                                            ] [         3]
[route2            ] [convertBodyTo1    ] [convertBodyTo[java.io.File]                                                   ] [         2]

Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------

org.apache.camel.InvalidPayloadException: No body available of type: java.io.File but has value: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile@24c9ecc7 of type: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.StandardMultipartFile on: Message[ID-ntkachev-1509013331141-0-13]. …
Run Code Online (Sandbox Code Playgroud)

java spring type-conversion apache-camel spring-camel

5
推荐指数
2
解决办法
3万
查看次数