【发布时间】:2017-07-19 00:28:23
【问题描述】:
当我在启用发现客户端的情况下尝试重新启动失败的批处理作业时遇到问题。如果我没有@EnableDiscoveryClient,每件事都可以正常工作,但是当我启用它时,我得到了
com.thoughtworks.xstream.converters.ConversionException: Cannot construct type
---- Debugging information ----
message : Cannot construct type
cause-exception : java.lang.InstantiationException
cause-message : java.util.Map$Entry
construction-type : java.util.Map$Entry
class : java.util.Map$Entry
required-type : java.util.Map$Entry
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /map/map/entry
line number : -1
class[1] : java.util.HashMap
converter-type[1] : com.thoughtworks.xstream.converters.collections.MapConverter
version : 1.4.9
-------------------------------
我在尝试反序列化(in)时跟踪错误,发现它在JdbcExecutionContextDao中
private class ExecutionContextRowMapper implements RowMapper<ExecutionContext> {
@Override
public ExecutionContext mapRow(ResultSet rs, int i) throws SQLException {
ExecutionContext executionContext = new ExecutionContext();
String serializedContext = rs.getString("SERIALIZED_CONTEXT");
if (serializedContext == null) {
serializedContext = rs.getString("SHORT_CONTEXT");
}
Map<String, Object> map;
try {
ByteArrayInputStream in = new ByteArrayInputStream(serializedContext.getBytes("ISO-8859-1"));
map = serializer.deserialize(in);
}
catch (IOException ioe) {
throw new IllegalArgumentException("Unable to deserialize the execution context", ioe);
}
for (Map.Entry<String, Object> entry : map.entrySet()) {
executionContext.put(entry.getKey(), entry.getValue());
}
return executionContext;
}
}
检查serializer 的版本和类型并没有让我发现任何事情,因为两者都是相同的,我正在尝试反序列化相同的字符串
{"map":[{"entry":[{"string":"activeSheetId","int":-1},{"string":"acceptPendingDelete","int":-1},{"string":"expiryDateValue","long":7},{"string":"decreaseGracePeriod","long":0},{"string":"countryList","set":[""]},{"string":"acceptRemovedPrefix","int":-1},{"string":"increaseGracePeriod","long":7},{"string":"highPeriod","long":14},{"string":["carrierName","XXXX"]},{"string":"acceptRemovedCountry","int":-1},{"string":"acceptFutureIgnore","int":-1},{"string":"carrierId","long":1168},{"string":"highIncreaseValue","long":2}]}]}
【问题讨论】:
-
你有针对上下文存储的序列化器定制吗?
-
不,我没有。当
@EnableDiscoveryClient被禁用时,上面相同的序列化字符串将起作用 -
您是否也只有在启动时才有此异常?您是否在应用程序启动时立即运行批处理作业?
-
目前在测试中我正在做的工作是在开始时自动运行,但是当我试图通过休息请求重新启动工作时问题就开始了,所以我认为它不相关,我会仔细检查虽然
-
您有示例说明这一点吗?
标签: spring-boot spring-batch spring-cloud spring-cloud-netflix