what’s the best way to insert and update data from the same table in spring batch?

You can remove the CustomerClassifier and define the composite item processor as follows:

public ClassifierCompositeItemProcessor<Customer, Customer> classifierCustomerCompositeItemProcessor(
        EvenCustomerProcessor evenCustomerProcessor,
        OddCustomerProcessor oddCustomerProcessor
) {
    ClassifierCompositeItemProcessor<Customer, Customer> itemProcessor = new ClassifierCompositeItemProcessor<>();
    itemProcessor.setClassifier(new Classifier<Customer, ItemProcessor<?, ? extends Customer>>() {
        public ItemProcessor<?, ? extends Customer> classify(Customer customer) {
            return customer.getStatus().equals("I") ? evenCustomerProcessor : oddCustomerProcessor;
    return itemProcessor;

Then update your step definition as follows:

public Step step1() throws Exception {
    return stepBuilderFactory.get("step1")
            .<Customer, Customer> chunk(10)
            .processor(classifierCustomerCompositeItemProcessor(evenCustomerProcessor(), oddCustomerProcessor()))

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top