java Spring 集成:没有可用的输出通道或回复通道标头
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29274479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring Integration: no output-channel or replychannel header available
提问by Blue
I wrote a simple spring integration application that moves files from one directory to another, it looks like this:
我写了一个简单的 spring 集成应用程序,将文件从一个目录移动到另一个目录,它看起来像这样:
@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;
}
It works perfectly well, but every copy operation gives me this exception
它工作得很好,但每次复制操作都会给我这个例外
2015-03-26 09:56:39.222 INFO 4772 --- [ask-scheduler-5] o.s.i.file.FileReadingMessageSource : Created message: [GenericMessage [payload=D:\TestIn.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)
I read in another topic that this happens when you filter out the headers somewhere in your code, but the first line of this trace tells me, that the only headers generated are id and timestamp.
我在另一个主题中读到,当您过滤掉代码中某处的标头时会发生这种情况,但此跟踪的第一行告诉我,生成的标头仅是 id 和时间戳。
采纳答案by Artem Bilan
Everything looks good, but no: you don't face the filter out the headers somewhere
issue.
一切看起来都很好,但不是:你没有面对这个filter out the headers somewhere
问题。
That's just because FileWritingMessageHandler
is request/reply
by default.
这只是因为FileWritingMessageHandler
是request/reply
在默认情况下。
To achieve you just move
requirement you should add this:
为了满足您的just move
要求,您应该添加以下内容:
handler.setExpectReply(false);
The code from that components looks like:
该组件的代码如下所示:
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;
So, it tries to send resultFile
to the outputChannel
of the endpoint for that @ServiceActivator
. Since you don't have such an option and there is no replyChannel
header you end up with that Exception.
因此,它尝试将 发送resultFile
到outputChannel
端点的@ServiceActivator
。由于您没有这样的选项并且没有replyChannel
标题,因此您最终会遇到该异常。