Spring Batch,JdbcExecutionContextDao java.util.Map $ Entry deserializer issue,xstream 1.4.1 [英] Spring Batch, JdbcExecutionContextDao java.util.Map$Entry deserializer issue, xstream 1.4.1
问题描述
使用Spring Batch 2.1.9时遇到问题:
当我使用 jobExplorer.getJobExecution(jobExecutionId)时,我发现DAO必须反序列化字符串时出现问题:
I have a problem using Spring Batch 2.1.9: when i use jobExplorer.getJobExecution(jobExecutionId), i find a problem when DAO has to deserialize a string like:
{"map":[{"entry":{"string":"parsedComparingDate","date":"2014-03-08 23:00:00.0 UTC"}}]}
来自 BATCH_JOB_EXECUTION_CONTEXT table,using method JdbcJobExecutionDao.getJobExecution()
。
from the BATCH_JOB_EXECUTION_CONTEXT table, using method JdbcJobExecutionDao.getJobExecution()
.
我知道spring批处理使用xstream 1.3,但是在我的Pom中,我有:
I know that spring batch uses xstream 1.3, but in my Pom, i have:
- spring-batch 2.1.9 ;
- xstream 1.4.1 (继承自smooks);
- jettison 1.3.3 (继承自cxf);
- spring-batch 2.1.9;
- xstream 1.4.1 (inherited from smooks);
- jettison 1.3.3 (inherited from cxf);
另外,我读到xstream 1.3在使用jettison 1.3.3时效果不佳,但是使用xstream 1.3 (从pom中排除xstream 1.4.1)工作正常,而使用xstream 1.4.1或major,我发现以下异常:
Also, i read that xstream 1.3 does not work fine with jettison 1.3.3, but using xstream 1.3 (excluding xstream 1.4.1 from pom) the job works correctly, while, using xstream 1.4.1 or major, i find the following exception:
Caused by: java.lang.InstantiationError: java.util.Map$Entry
at sun.reflect.GeneratedSerializationConstructorAccessor1.newInstance(Unknown Source) [:1.6.0_23]
at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [rt.jar:1.6.0_23]
at com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider.newInstance(Sun14ReflectionProvider.java:75) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.instantiateNewInstance(AbstractReflectionConverter.java:424) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:229) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:71) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.converters.collections.MapConverter.putCurrentEntryIntoMap(MapConverter.java:85) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.converters.collections.MapConverter.populateMap(MapConverter.java:77) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.converters.collections.MapConverter.populateMap(MapConverter.java:71) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.converters.collections.MapConverter.unmarshal(MapConverter.java:66) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1035) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1019) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:895) [xstream-1.4.1.jar:]
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:886) [xstream-1.4.1.jar:]
at org.springframework.batch.core.repository.dao.XStreamExecutionContextStringSerializer.deserialize(XStreamExecutionContextStringSerializer.java:48) [spring-batch-core-2.1.9.RELEASE.jar:]
at org.springframework.batch.core.repository.dao.JdbcExecutionContextDao$ExecutionContextRowMapper.mapRow(JdbcExecutionContextDao.java:222) [spring-batch-core-2.1.9.RELEASE.jar:]
at org.springframework.batch.core.repository.dao.JdbcExecutionContextDao$ExecutionContextRowMapper.mapRow(JdbcExecutionContextDao.java:215) [spring-batch-core-2.1.9.RELEASE.jar:]
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:92) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:60) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:649) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:587) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:666) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:674) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:714) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.query(SimpleJdbcTemplate.java:202) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.query(SimpleJdbcTemplate.java:209) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.batch.core.repository.dao.JdbcExecutionContextDao.getExecutionContext(JdbcExecutionContextDao.java:106) [spring-batch-core-2.1.9.RELEASE.jar:]
1)我看过代码,可以配置< STRONG> XStreamExecutionContextStringSerializer 为了设置 reflectionProvider = null (这样,它不会使用Provider)?
1) i have seen the code, can i configure the XStreamExecutionContextStringSerializer in order to set reflectionProvider = null (in this way, it will not uses the Provider) ?
2)那里是解决我问题的其他解决方案吗?
2) there are other solutions to fix my problem ?
谢谢
推荐答案
这是我无法更改xstream版本和jettison版本,因为它们是由其他组件导入的(如smooks)。
It's impossible for me to change xstream version and jettison version because they imported by other components (like smooks).
可能的解决方案是创建两个不同的 JBoss模块并使用它们来理解。
A possible solution could be to create two different JBoss modules and to use them togheter.
所以,我找到了另一个解决方案:使用 spring-batch 2.2.0.RELEASE ,使用 org.springframework.batch.core.repository.dao.DefaultExecutionContextSerializer
作为序列化程序而不是 XStream 。
So, i find another solution: use spring-batch 2.2.0.RELEASE, and use org.springframework.batch.core.repository.dao.DefaultExecutionContextSerializer
as serializer instead of XStream.
配置下方:
<bean id="batchDefaultSerializer" class="org.springframework.batch.core.repository.dao.DefaultExecutionContextSerializer" />
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="batchTransactionManager" />
<property name="lobHandler" ref="defaultLobHandler" />
<property name="serializer" ref="batchDefaultSerializer" />
</bean>
<bean id="jobExplorer"
class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="serializer" ref="batchDefaultSerializer" />
</bean>
我测试了它并且工作正常,所以,我认为这是最好的解决方案。
I tested it and it works fine, so, i think it's the best solution.
这篇关于Spring Batch,JdbcExecutionContextDao java.util.Map $ Entry deserializer issue,xstream 1.4.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!