簡體   English   中英

Spring Integration DSL - 可以訪問標頭的出站網關

[英]Spring Integration DSL - Outbound Gateway with access to Headers

我遇到了Spring Integration的問題。 我正在使用Spring Boot 1.4.0.RELEASE,Spring Integration 4.3.1.RELEASE,Spring Integration DSL 1.2.0.M1。

我正在嘗試做什么:

我正在編寫一個應用程序,它將從FTP和本地文件系統讀取文件(使用入站通道適配器),將文件傳輸到本地工作目錄(使用文件出站網關),處理,然后將它們移動到最終目的地(文件出站)網關/適配器)。

編輯:原始問題源於OutboundGateway錯誤使用。 有關我做錯的詳細信息,請查看編輯歷史記錄。

我在連接需要來自郵件頭的信息的OutboundGateway遇到問題。

我的基本流程是:

@Bean
@SuppressWarnings("unchecked")
public IntegrationFlow fileSystemReadingFlow() {
    LOGGER.debug("Building fileSystemReadingFlow.");
    // Create a FileInboundChannelAdapter

        return IntegrationFlows.from(s -> s.file(new File(StringUtils.cleanPath(Paths.get(directoryProperties.getLocal() , UNKNOWN).toString())))
                        // Add a Filter to restrict which files are retrieved
                        .filter(fileListFilterBuilder.buildFileListFilter(File.class))
                // Add a poller to continually watch the directory
                , endpointConfigurer -> endpointConfigurer.poller(poller)
        )
                .enrichHeaders(h -> h.header(FOLDER_NAME, LOCAL))
                .handle((message, headers) -> Files.outboundGateway(new File( StringUtils.cleanPath(Paths.get(directoryProperties.getWorking()
                                    , (String) headers.get(FOLDER_NAME)).toString()))).deleteSourceFiles(true).autoCreateDirectory(true) )
                // Send the files to the aggregatingChannel
                .channel("aggregatingFileChannel")
                .get();
  }

問題是handle((message, headers) -> Files.outboundGateway(...)部分。使用上面的lambda方法一遍又一遍地吐出這個錯誤。

ErrorMessage [payload=org.springframework.messaging.MessagingException: failed to resolve channel name 'org.springframework.integration.dsl.file.FileWritingMessageHandlerSpec'; nested exception is org.springframework.messaging.core.DestinationResolutionException: failed to look up MessageChannel with name 'org.springframework.integration.dsl.file.FileWritingMessageHandlerSpec' in the BeanFactory.; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.integration.dsl.file.FileWritingMessageHandlerSpec' is defined, headers={id=e3f5f341-6379-0dd0-11e6-e4bff8f455b0, timestamp=1471619276894}]

文檔和我的測試表明,定義它如下所示。 但是,如何訪問標題?

.handle(Files.outboundGateway(new File( "someDir"))).deleteSourceFiles(true).autoCreateDirectory(true) )

我已經嘗試使用SpEl表達式,這可能是正確的方法,但我沒有讓它工作。

.handle(Files.outboundGateway("StringUtils.cleanPath(Paths.get(directoryProperties.getWorking()" +
                                    ", headers[FOLDER_NAME]).toString())").deleteSourceFiles(true).autoCreateDirectory(true) )

重新閱讀SpEL參考后,我能夠找出問題所在。 我需要顯式引用我需要調用的靜態方法,然后正確地轉義文字。

.handle(Files.outboundGateway("T(org.springframework.util.StringUtils).cleanPath(T(java.nio.file.Paths).get('" +directoryProperties.getWorking() +"'" +
                                    ", headers['"+FOLDER_NAME+"']).toString())").deleteSourceFiles(true).autoCreateDirectory(true) )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM