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;
}
}
-
Can you share your productFlatFileReader configuration?Serkan Arıkuşu– Serkan Arıkuşu2012年10月08日 07:47:23 +00:00Commented 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?firefox784– firefox7842012年10月15日 22:26:42 +00:00Commented Oct 15, 2012 at 22:26
1 Answer 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" />