0

我必须根据标头属性将文件写入多个子目录。没有办法在 Spring Integration 中配置它。

@Bean
@ServiceActivator(inputChannel = "processingChannel")
public MessageHandler processingDirectory() {
    FileWritingMessageHandler handler = new FileWritingMessageHandler(new File("some-path"));
    handler.setFileExistsMode(FileExistsMode.REPLACE);
    handler.setExpectReply(false);
    handler.setPreserveTimestamp(true);
    handler.setTemporaryFileSuffix(".writing");
    handler.setAutoCreateDirectory(true);
    return handler;
}

这个 bean 接收一个文件以及一些标题属性,即来自 "processingChannel" 的 type="abc" 。文件已成功写入某个路径。但我的要求是根据“类型”值写入 somepath/abc 或 somepath/xyz 位置

4

1 回答 1

0

使用 SpEL 表达式

new FileWritingMessageHandler(new SpelExpressionParser().parseExpression(
    "headers['someHeaderWithTheDestinationPath']"));
于 2020-07-27T13:35:51.177 回答