【问题标题】:How to write files dynamically into subdirectory by FileWritingMessageHandler如何通过 FileWritingMessageHandler 将文件动态写入子目录
【发布时间】:2020-11-15 02:11:37
【问题描述】:

我必须根据标题属性将文件写入多个子目录。 没有办法在 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 位置

【问题讨论】:

    标签: file spring-integration message-handlers


    【解决方案1】:

    使用 SpEL 表达式

    new FileWritingMessageHandler(new SpelExpressionParser().parseExpression(
        "headers['someHeaderWithTheDestinationPath']"));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-13
      相关资源
      最近更新 更多