对于文件读取消息源入站适配器和带注释的转换器配置如下
@Bean
@InboundChannelAdapter(autoStartup = "false", value = "incomingchannel", poller = @Poller("custompoller"))
public MessageSource<File> fileReadingMessageSource() {
}
@Transformer(inputChannel = "incomingchannel", outputChannel = "jobLaunchChannel")
public JobLaunchRequest toRequest(Message<File> message) throws Exception {
}
现在我想更改变压器以引用出站网关的回复通道,即将文件从一个目录移动到另一个目录,即将文件从incomingchannel目录移动到另一个目录,并处理或转换他的文件或执行一些验证
<file:outbound-gateway id="mover" request-channel="incomingchannel" reply-channel="newdirectory" directory="<<path to new directory file to be moved" delete-source-files="true"/>
有人将上述 XML 配置转换为注释配置或任何想法吗?
注释配置后,我将不得不更改转换器输入通道以引用新目录通道,即消息网关的回复通道...
在此先感谢您提供有关此问题的任何帮助或建议
--- 试用 Artem 链接中提供的片段后更新 1
@Bean
@ServiceActivator(inputChannel = "incomingchannel")
public MessageHandler fileWritingMessageHandler() {
FileWritingMessageHandler handler = new FileWritingMessageHandler(new File(newdirectorypath));
handler.setFileExistsMode(FileExistsMode.APPEND);
handler.setDeleteSourceFiles(true);
return handler;
}
@MessagingGateway(defaultRequestChannel = "incomingchannel", defaultReplyChannel = "newdirectorychannel")
public interface MyGateway {
void writeToFile(@Header(FileHeaders.FILENAME) String fileName, @Header(FileHeaders.FILENAME) File directory,
String data);
}
但是遇到了两个问题
入站适配器正在尝试将目录也作为文件轮询(使用递归目录扫描器) - 如何确保不将目录作为文件轮询
嵌套异常是
org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available, failedMessage=GenericMessage [payload=C