How to java-configure separate datasources for spring batch data and business data? Should I even do it?

Ok, this is strange but it works. Moving the datasources to it’s own configuration class works just fine and one is able to autowire. The example is a multi-datasource version of Spring Batch Service Example: DataSourceConfiguration: public class DataSourceConfiguration { @Value(“classpath:schema-mysql.sql”) private Resource schemaScript; @Bean @Primary public DataSource hsqldbDataSource() throws SQLException { final SimpleDriverDataSource dataSource … Read more

Spring Batch – Using an ItemWriter with List of Lists

Typically, the design pattern is: Reader -> reads something, returns ReadItem Processor -> ingests ReadItem, returns ProcessedItem Writer -> ingests List<ProcessedItem> If your processor is returning List<Object>, then you need your Writer to expect List<List<Object>>. You could do this by wrapping your JdbcBatchItemWriter as a delegate in an ItemWriter that looks something like this: public … Read more

Spring-Batch without persisting metadata to database?

Simply create a configuration without datasource for Batch configuration : @Configuration @EnableAutoConfiguration @EnableBatchProcessing public class BatchConfiguration extends DefaultBatchConfigurer { @Override public void setDataSource(DataSource dataSource) { // override to do not set datasource even if a datasource exist. // initialize will use a Map based JobRepository (instead of database) } } It will initialize JobRepository and … Read more

How can we share data between the different steps of a Job in Spring Batch?

the job repository is used indirectly for passing data between steps (Jean-Philippe is right that the best way to do that is to put data into the StepExecutionContext and then use the verbosely named ExecutionContextPromotionListener to promote the step execution context keys to the JobExecutionContext. It’s helpful to note that there is a listener for … Read more