gpt4 book ai didi

java - Spring Integration DSL - 可访问 header 的出站网关

转载 作者:搜寻专家 更新时间:2023-11-01 03:18:33 25 4
gpt4 key购买 nike

我遇到了 Spring Integration 的问题。我正在使用 Spring Boot 1.4.0.RELEASE、Spring Integration 4.3.1.RELEASE、Spring Integration DSL 1.2.0.M1。

我正在尝试做的事情:

我正在编写一个应用程序,它将从 FTP 和本地文件系统(使用入站 channel 适配器)读取文件,将文件传输到本地工作目录(使用文件出站网关),处理,然后将它们移动到最终目的地(文件出站网关/适配器)。

编辑:最初的问题源于 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) )

关于java - Spring Integration DSL - 可访问 header 的出站网关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39041341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com