Search code examples
spring-integrationspring-integration-dsl

File Inbound Adapter example provided in sample not working


@SpringBootApplication
public class FileReadingJavaApplication {

    public static void main(String[] args) {
        new SpringApplicationBuilder(FileReadingJavaApplication.class)
            .web(false)
            .run(args);
    }

    @Bean
    public IntegrationFlow fileReadingFlow() {
         return IntegrationFlows
                  .from(s -> s.file(new File(INBOUND_PATH))
                              .patternFilter("*.txt"),
                          e -> e.poller(Pollers.fixedDelay(1000)))
                  .transform(Files.toStringTransformer())
                  .channel("processFileChannel")
                  .get();
        }

}

Reads following error in eclipse: Multiple markers at this line - The target type of this expression must be a functional interface - The method from(String, boolean) in the type IntegrationFlows is not applicable for the arguments (( s) -> {}, ( e) -> {})


Solution

  • Sounds like you use Spring Integration 5.x already. There is no that factory for channel Adapters to avoid cyclic dependency. You need to use Files.inboundAdaper() instead of that first lambda.

    See the migration guide: https://github.com/spring-projects/spring-integration/wiki/Spring-Integration-4.3-to-5.0-Migration-Guide

    Also, please, raise an issue on GitHub to fix that sample in the docs: https://docs.spring.io/spring-integration/docs/5.1.3.BUILD-SNAPSHOT/reference/html/files.html#_configuring_with_the_java_dsl_8

    See a sample configuration in the test case: https://github.com/spring-projects/spring-integration/blob/master/spring-integration-file/src/test/java/org/springframework/integration/file/dsl/FileTests.java

    Plus you can find some of them in the samples: https://github.com/spring-projects/spring-integration-samples