gpt4 book ai didi

spring-batch - 将流作为参数传递给作业

转载 作者:行者123 更新时间:2023-12-05 01:12:53 24 4
gpt4 key购买 nike

有没有办法在通过作业启动器启 Action 业时传递流,类似于传递作业参数?

我有一个单独的服务来获取文件,然后我想启动批处理作业来加载它。

代码场景:

考虑这个 sample .此处定义了作业,但实际启动器驻留在依赖项 underneath 中.

所以考虑在 sample ,我添加了一个 Controller ,它读取用户的输入文件,然后触发 sample 中定义的示例作业由 underneath 的 joblauncher.run 运行.

我正在考虑将此文件流直接传递给作业的读取器,而不是将其写入外部磁盘并在 Reader 的 setSeResource 中读取

最佳答案

查看您提供的示例代码后,我认为您可以执行以下操作:

1)在SimpleJobConfiguration中声明一个静态HashMap类(class)。

public static Map<String, Object> customStorage = new HashMap<String, Object>();

2) 从您的服务中填充此 map
SimpleJobConfiguration.customStorage.put("key", yourStream);

3)在 setResource中使用这个静态 map 您的方法 ItemReader (如您之前的问题所述)
@Override
public void setResource(Resource resource) {

// Get your stream from the static map
Byte[] stream = (Byte[]) SimpleJobConfiguration.customStorage.get("key");

// Convert byte array to input stream
InputStream is = new ByteArrayInputStream(stream);

// Create springbatch input stream resource
InputStreamResource res = new InputStreamResource(is);

// Set resource
super.setResource(res);
}

此解决方案仅在您的服务位于 jobLauncher 旁边时才有效。

关于spring-batch - 将流作为参数传递给作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33340367/

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