Migration to Spring Boot 2 and using Spring Batch 4

前端 未结 3 497
心在旅途
心在旅途 2020-12-09 23:46

I am migrating Spring Boot from 1.4.2 to 2.0.0, which also includes migrating Spring batch from 3.0.7 to 4.0.0 and it looks like batch process is no longer working when i tr

3条回答
  •  隐瞒了意图╮
    2020-12-10 00:35

    Based on Michael's answer above, this code block worked for me to extend the default configuration — I had to wire up the Serializer to both the JobRepository.class and the JobExplorer.class:

    @Configuration
    @EnableBatchProcessing
    MyBatchConfigurer extends DefaultBatchConfigurer {
        private final DataSource dataSource;
    
        @Autowired
        public BatchConfiguration(final DataSource dataSource) throws Exception {
            this.dataSource = dataSource;
        }
    
        @Bean
        ExecutionContextSerializer getSerializer() {
            return new XStreamExecutionContextStringSerializer();
        }
    
    
        @Override
        protected JobRepository createJobRepository() throws Exception {
            final JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
            factory.setDataSource(dataSource);
            factory.setSerializer(getSerializer());
            factory.setTransactionManager(getTransactionManager());
            factory.afterPropertiesSet();
            return factory.getObject();
        }
    
        @Override
        protected JobExplorer createJobExplorer() throws Exception {
            final JobExplorerFactoryBean jobExplorerFactoryBean = new JobExplorerFactoryBean();
            jobExplorerFactoryBean.setDataSource(dataSource);
            jobExplorerFactoryBean.setSerializer(getSerializer());
            jobExplorerFactoryBean.afterPropertiesSet();
            return jobExplorerFactoryBean.getObject();
        }
    }
    

提交回复
热议问题