当您的作业的执行上下文使用版本3(
XStream默认使用)序列化,然后使用版本4(
Jackson默认使用)反序列化时,会发生此错误。因此,要么将SpringBatch降级到版本3,要么将您的作业存储库配置为使用
XStreamExecutionContextStringSerializer。
在您的情况下,您已经定义了类型的Bean
BatchConfigurer,因此您可以覆盖该
createJobRepository方法并配置XStream序列化器。例如:
@BeanBatchConfigurer 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(); } };}


