Spring Batch, JdbcExecutionContextDao java.util.Map$Entry deserializer issue, xstream 1.4.1

旧城冷巷雨未停 提交于 2019-12-03 15:21:28

It's impossible for me to change xstream version and jettison version because they imported by other components (like smooks).

A possible solution could be to create two different JBoss modules and to use them togheter.

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.

Below the configuration:

<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.

Due to the incompatibility of Jettison 1.2+ with XStream, upgrading XStream will cause Spring Batch to break. This is something that was recently identified but has not been addressed yet. The solution for your issue is to use Jettison 1.2 and XStream 1.4.7

I'm using Spring Boot 1.4.0 with Spring Batch 3.0.7 and ran into this problem with a microservice that is using the Netflix OSS components b/c they use XStreams 1.4.2.

I'm also using Java configuration instead of XML. Here's what I came up with to solve the issue: In a @Configuration class:

   @Bean
   public ExecutionContextSerializer serializer()
   {
      return new Jackson2ExecutionContextStringSerializer();
   }

   @Bean
   @Autowired
   public JobRepository jobRepository( DataSource dataSource, 
                                       PlatformTransactionManager txManager ) throws Exception
   {
        JobRepositoryFactoryBean fac = new JobRepositoryFactoryBean();
        fac.setDataSource( dataSource );
        fac.setTransactionManager( txManager );
        fac.setSerializer( serializer() );
        fac.afterPropertiesSet();
        return fac.getObject();
   }

   @Bean
   @Autowired
   public JobExplorer jobExplorer( DataSource dataSource ) throws Exception
   {
      JobExplorerFactoryBean fac = new JobExplorerFactoryBean();
      fac.setDataSource( dataSource );
      fac.setSerializer( serializer() );
      fac.afterPropertiesSet();
      return fac.getObject();
   }

I'm using Postgres as a backing store, so the DefaultExecutionContextSerializer didn't work as it tried to serialize binary instead of UTF-8 (JSON).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!