有一个 spring 批处理作业,它将 map/list 存储在 jobexeutioncontext 中以用于 biz 逻辑,如果它第一次失败并尝试重新启动它,它总是发生如下错误:
java.lang.InstantiationError: java.util.Map$Entry
at sun.reflect.GeneratedSerializationConstructorAccessor147.newInstance(Unknown Source)
....
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:853)
at org.springframework.batch.core.repository.dao.XStreamExecutionContextStringSerializer.deserialize(XStreamExecutionContextStringSerializer.java:48)
原因当它从 DB CLOB 读取 jobexecutioncontext 看起来像 XStream 1.3 的反序列化问题......
我尝试了降级到 XStream 1.2.2 之类的方法,但根本没有用。所以我修复了将地图/列表存储在下面的jobexecutioncontext中的批处理程序
AfterJobListener 类
protected void afterJob() {
for (Entry<String, Object entry : getJobExecutionContext().entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
//log.debug("key:" + key + ", value:" + value);
if (value instanceof Map || value instanceof List) {
//log.debug("Del key:" + key + ",Del value:" + value);
getJobExecutionContext().remove(key);
}
}
}
jobRepository.updateExecutionContext(getJobExecution());
现在正在工作。
所以问题是 - 还有另一种方法可以逃避这个错误吗?我的网站在 websphere 7.0.0.17 上使用 spring-batch-core-2.1.5 springframework-core 3.0.2
谢谢