如何通过Java配置创建int-file:outbound网关

时间:2016-01-13 02:51:39

标签: java spring-integration

我正在尝试将XML中的file:outbound-gateway配置转换为Java配置,但无法找到正确的API。

XML:

<file:outbound-gateway directory="file:myDir"
    request-channel="inFiles" auto-create-directory="true"
    delete-source-files="true" reply-channel="outFiles">
</file:outbound-gateway>

这是我迄今为止在Java配置上所拥有的。不确定如何设置request-channelreply-channel

@Bean
public MessageHandler fileOutBoundGateway() {
    FileWritingMessageHandler gateway = new FileWritingMessageHandler(new File("myDir"));
    gateway.setDeleteSourceFiles(true);
    gateway.setAutoCreateDirectory(true);

    // FIXME need to set request and reply channel
    return gateway;
}

1 个答案:

答案 0 :(得分:1)

request-channelinputChannel)是endpoint的选项。在您的情况下,您只有channelMessageHandler,但仍然没有endpoint

只有你需要的是service-activator

@Bean
@ServiceActivator(inputChannel = "input")
public MessageHandler fileOutBoundGateway() {
    FileWritingMessageHandler gateway = new FileWritingMessageHandler(new File("myDir"));
    gateway.setDeleteSourceFiles(true);
    gateway.setAutoCreateDirectory(true);
    gateway.setOutputChannel(outputChannel());
    return gateway;
}

请在Reference Manual中找到更多信息。 另请注意Java DSL