4

I am creating a Spring Batch job using the Spring Batch template included with STS 2.81 and using examples from Spring Batch in Action by Manning. I am able to execute the chunk reader and writer without problems, but my code is skipping the processor. I have even tried nulling out all objects as it gets in the processor and nothing, the objects still manage to get written as if the processor is ignored. I tried calling the System.out.println within the Processor but nothign gets printed out in the terminal. I finally changed the configuration from using an XML bean to a Component via annotation and it did not work either. I am not sure if there is some setting that I am missing out...I followed examples in both Spring Batch in Action and from the SpringSource website and everything look ok...help!

Here's the code:

<batch:job id="job1">
 <batch:step id="step1" > 
 <batch:tasklet transaction-manager="transactionManager" start-limit="100" >
 <batch:chunk reader="productFlatFileReader"
 processor="productProcessor"
 writer="productFlatFileWriter"
 commit-interval="10" />
 </batch:tasklet>
 </batch:step>
</batch:job>

Here's the processor bean:

<bean id="productProcessor" class="com.test.training.processors.ProductProcessor" />

This is the Processor class that I am trying to execute with no avail:

package com.test.training.processors;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.stereotype.Component;
import com.test.training.entities.Product;
public class ProductProcessor implements ItemProcessor<Product, Product> {
@Override
public Product process(Product product) throws Exception {
 product.setDescription("Processor is WORKING!");
 return product;
 //return this.validateProductByProductIdentifier(product) ? null : product;
}
private boolean validateProductByProductIdentifier(Product product) {
 return product.getProduct_identifier() == 5 ? true : false;
}
}
asked Oct 6, 2012 at 1:46
2
  • Can you share your productFlatFileReader configuration? Commented Oct 8, 2012 at 7:47
  • As Serkan asked , the flat file reader and the related line mapper configurations would give more insight to the issue. Is the entity built from each line of the flat file is also Product? Commented Oct 15, 2012 at 22:26

1 Answer 1

-1

Your bean configuration needs to have scope="step" for Spring Batch to recognize bean as a batch bean.

Like:

<bean id="productProcessor" scope="step" class="com.test.training.processors.ProductProcessor" />
answered Sep 10, 2013 at 10:25
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.