Java Spring集成:没有可用的输出通道或replychannel标头
我编写了一个简单的spring集成应用程序,可以将文件从一个目录移动到另一个目录,如下所示:Java Spring集成:没有可用的输出通道或replychannel标头,java,spring,spring-integration,Java,Spring,Spring Integration,我编写了一个简单的spring集成应用程序,可以将文件从一个目录移动到另一个目录,如下所示: @Bean @InboundChannelAdapter(value="requestChannel", poller = @Poller(fixedDelay="100")) public FileReadingMessageSource adapter(){ FileReadingMessageSource source = new FileReadingMessageSource();
@Bean
@InboundChannelAdapter(value="requestChannel", poller = @Poller(fixedDelay="100"))
public FileReadingMessageSource adapter(){
FileReadingMessageSource source = new FileReadingMessageSource();
source.setDirectory(new File("D:/TestIn"));
return source;
}
@Bean
MessageChannel requestChannel(){
return new DirectChannel();
}
@Bean
@ServiceActivator(inputChannel="requestChannel")
public FileWritingMessageHandler handle(){
FileWritingMessageHandler handler = new FileWritingMessageHandler(new File("D:/TestOut"));
handler.setDeleteSourceFiles(true);
return handler;
}
它工作得非常好,但每次复制操作都会给我这个例外
2015-03-26 09:56:39.222 INFO 4772 --- [ask-scheduler-5] o.s.i.file.FileReadingMessageSource : Created message: [GenericMessage [payload=D:\TestIn\9.txt, headers={id=d8b27257-0a90-b7ad-65cb-85e93668fb5a, timestamp=1427360199222}]]
2015-03-26 09:56:39.223 ERROR 4772 --- [ask-scheduler-5] o.s.integration.handler.LoggingHandler : org.springframework.messaging.MessagingException: ; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available
at org.springframework.integration.dispatcher.AbstractDispatcher.wrapExceptionIfNecessary(AbstractDispatcher.java:133)
我在另一个主题中读到,当您过滤掉代码中某个地方的头时,会发生这种情况,但此跟踪的第一行告诉我,生成的头只有id和时间戳。一切看起来都很好,但没有:您不会面临
过滤掉某个地方的头的问题
这只是因为默认情况下,FileWritingMessageHandler
是request/reply
要实现您的只需移动要求,您应添加以下内容:
handler.setExpectReply(false);
该组件的代码如下所示:
if (!this.expectReply) {
return null;
}
if (resultFile != null) {
if (originalFileFromHeader == null && payload instanceof File) {
return this.getMessageBuilderFactory().withPayload(resultFile)
.setHeader(FileHeaders.ORIGINAL_FILE, payload);
}
}
return resultFile;
因此,它尝试将resultFile
发送到该@ServiceActivator
的端点的outputChannel
。由于您没有这样的选项,并且没有replyChannel
标题,因此您最终会遇到该异常。我从何处捕获“预期答复”或引发的异常?听起来像是一个新的SO问题?抱歉,需要更多的上下文。简而言之:在大多数情况下,Spring集成只是Java。所以,你从调用它的代码中捕捉到一个异常。是的,我可以,但我认为它与此相关。通过Handler.setExpectReply(true),我可以从文档中读到:“指定handle方法是否应该返回应答。默认值为‘true’。”。但是,由于该方法使用的是“Bean”和“ServiceActivator”注释,我从何处获取返回的回复呢?@ServiceActivator
具有outputChannel
属性。新的SO问题真的会更好:社区得到一个问题和解决方案;回答的人会得到名声。每个人都在赢得新的问题: