Spring Batch

Spring Batch logs what it has done to some tables that are documented at Meta-Data Schema. The SQL script for creating these is stored in the Spring Batch Core JAR file. I have been working with Spring Batch 4.0.1 and so the file is called spring-batch-core-4.0.1.RELEASE.jar in my Maven repository. Then inside the archive you need to navigate to /org/springframework/batch/core and look for schema*.sql. I believe there is an easier way to use these but I have not found that, yet.

The source code for Spring Batch is on GitHub at spring-projects/spring-batch: Spring Batch is a framework for writing offline and batch applications using Spring and Java if you fancy a look and generally I believe reading the source code of a framework is always a good place to start.

Working with Listeners

Having just learnt Spring and Spring Batch by just getting on and working with them, there are a few things I was slow to pick up. MulticasterBatchListener (Spring Batch 4.0.1.RELEASE API)

    @Bean
    public Step mainStep(JdbcBatchItemWriter<MyItem> writer) throws SQLException {
        List<StepListener> stepListenerList = new ArrayList<StepListener>();
        stepListenerList.add(myItemItemWriteListener());
        stepListenerList.add(generalStepListener());

        MulticasterBatchListener multiListener = new MulticasterBatchListener();
        multiListener.setListeners(stepListenerList);

        return stepBuilderFactory.get("MainMyItemStep")
                .<MyItem, MyItem> chunk(10)
                .reader(readerOfMyItem(localDataSource()))
                .writer(writerOfMyItem(localDataSource()))
                .listener((StepExecutionListener)multiListener)
                .build();
    }
On important point to note here is that when you add the listener to the step by calling .listener() you need to cast it, I have used StepExecutionListener, there are other options.