Caused by: java.lang.IllegalArgumentException: Unable to deserialize the execution context in Spring Batch

一曲冷凌霜 提交于 2019-12-06 15:27:22

This error happens when the execution context of your job is serialized with version 3 (using XStream by default) and then deserialized with version 4 (using Jackson by default). So either downgrade Spring Batch to version 3 or configure your job repository to use the XStreamExecutionContextStringSerializer.

In your case, you have already defined a bean of type BatchConfigurer, so you can override the createJobRepository method and configure the XStream serializer. For example:

@Bean
BatchConfigurer configurer(@Qualifier("dataSource") DataSource dataSource, PlatformTransactionManager transactionManager) {
    return new DefaultBatchConfigurer(dataSource) {
        @Override
        protected JobRepository createJobRepository() throws Exception {
            JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
            factory.setDataSource(dataSource);
            factory.setTransactionManager(transactionManager);
            factory.setSerializer(new XStreamExecutionContextStringSerializer());
            factory.afterPropertiesSet();
            return factory.getObject();
        }
    };
}

Try cleaning up the spring batch tables. Use following link : --cleaning spring batch tables ---- http://forum.spring.io/forum/spring-projects/batch/122103-clean-spring-batch-metadata-tables

Since XStreamExecutionContextStringSerializer is deprecated with the latest Spring BATCH release.

If you are adding a complex object to Execution Context Check if the object you are trying to add is Serializable.

For example, if your class looks like:

class Sample{
String data;
List<DataItem> dataItems;

}

Make sure DataItem which is present inside the object is also Serializable.

This helped me solve my issue.

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