2017-06-13 77 views
0

我使用Spring集成的Java DSL v編譯出錯1.2.2及以下的一些例子我嘗試寫代碼來查詢一個文件夾輪詢 - 添加Files.inboundAdapter

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

並不清楚發生了什麼事情在你的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

+0

阿爾喬姆,你能說清楚我應該使用哪些依賴關係嗎?我現在不得不使用compile(「org.springframework.boot:spring-boot-starter-integration:1.5.4.RELEASE」),我不得不使用直接類型集成IntegrationFlows.from((MessageSourceSpec > )Files.inboundAdapter(directory) - 並且仍然獲得鏈接錯誤nowError:(105,38)java:can not access org.springframework.integration.file.FileReadingMessageSource not found。 –

+0

當涉及到添加DSL支持時,Spring集成doc似乎非常糟糕它只建議添加不包括DSL的編譯(「org.springframework.integration:spring-integration-core:4.3.10.RELEASE」)。 –

+0

您必須添加'Spring-Integration-file'。在Spring Integration中是獨立的jar,依賴項神器 –