使用Java DSL从文件轮询 - 添加Files.inboundAdapter时编译错误

时间:2017-06-13 14:45:49

标签: java spring spring-integration

我正在使用Spring Integration Java DSL v.1.2.2并按照一些示例尝试编写代码来轮询文件夹

    return IntegrationFlows
            .from(Files.inboundAdapter(new File("/tmp/foo")))
            .handle((p, h) -> fileProcessor.process(p))
            .get();

此代码无法编译,因为

"Cannot resolve method 'from(org.springframework.integration.dsl.
   file.FileInboundChannelAdapterSpec)'"

如何修复此问题以及如何添加固定间隔轮询?

1 个答案:

答案 0 :(得分:1)

不清楚IDE中发生了什么,但我们在测试用例中有这个示例:

@Bean
public IntegrationFlow fileToFile() {
    return IntegrationFlows.from(Files.inboundAdapter(new File("/tmp/in"))
                    .autoCreateDirectory(true)
                    .patternFilter("*.txt"),
            e -> e.poller(Pollers.fixedDelay(5000)))
            .transform(Transformers.fileToString())
            .transform("payload.replaceAll('\r\n', '\n')")
            .handle(Files.outboundAdapter("'/tmp/out'")
                    .autoCreateDirectory(true))
            .get();
}

fixedDelay()是对您关于fixed-interval的第二个问题的回答。

https://github.com/spring-projects/spring-integration-java-dsl/blob/master/src/test/java/org/springframework/integration/dsl/samples/file2file1/FileChangeLineSeparator.java