且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将流作为参数传递给作业

更新时间:2022-06-27 02:40:20

看过您提供的示例代码后,我认为您可以这样做:

1)在SimpleJobConfiguration类中声明静电哈希图。

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

2)从您的服务填充此地图

SimpleJobConfiguration.customStorage.put("key", yourStream);

3)在ItemReadersetResource方法中使用此静电地图(如您上一个问题所述)

@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旁边时,此解决方案才有效。