更新时间: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)在ItemReader
的setResource
方法中使用此静电地图(如您上一个问题所述)
@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旁边时,此解决方案才有效。