How does Spring Batch CompositeItemWriter manage transaction for delegate writers?

My first question is if CompositeItemWriter is a fit for the requirement above? Yes, CompositeItemWriter is the way to go. If yes, that lead to the second question about transaction. For example, if the first update is successful, and the second insert fails. Will the 1st update transaction be rolled back automatically? Otherwise, how to … Read more

Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/batch]

Run the job through CommandLineJobRunner: java -jar batchprimer-1.0.jar META-INF/spring/module-context.xml job1 even with a complete target folder you have to provide the classpath information for the java command, to ease the configuration you can try it with an all-in-one executable jar e.g. with maven-shade-plugin or an executable shell script (.bat/.sh) with all needed libraries, e.g. with … Read more

Spring Batch: One reader, multiple processors and writers

This solution is valid if your item should be processed by processor #1 and processor #2 You have to create a processor #0 with this signature: class Processor0<Item, CompositeResultBean> where CompositeResultBean is a bean defined as class CompositeResultBean { Processor1ResultBean result1; Processor2ResultBean result2; } In your Processor #0 just delegate work to processors #1 and … Read more

How to get access to job parameters from ItemReader, in Spring Batch?

As was stated, your reader needs to be ‘step’ scoped. You can accomplish this via the @Scope(“step”) annotation. It should work for you if you add that annotation to your reader, like the following: import org.springframework.batch.item.ItemReader; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component(“foo-reader”) @Scope(“step”) public final class MyReader implements ItemReader<MyData> { @Override public MyData read() throws Exception … Read more

Spring Batch With Annotation and Caching

A JobExecutionListener can be used to populate the cache with reference data before the job is executed and clear the cache after the job is finished. Here is an example: import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobExecutionListener; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.tasklet.Tasklet; import … Read more

Spring-batch @BeforeStep does not work with @StepScope

When you configure a bean as follows: @Bean @StepScope public MyInterface myBean() { return new MyInterfaceImpl(); } You are telling Spring to use the proxy mode ScopedProxyMode.TARGET_CLASS. However, by returning the MyInterface, instead of the MyInterfaceImpl, the proxy only has visibility into the methods on the MyInterface. This prevents Spring Batch from being able to … Read more

Spring batch Job read from multiple sources

There isn’t a ready-to-use component that perform what you ask; the only solution is to write a custom ItemReader<> that delegates to JdbcCursorItemReader (or to HibernateCursorItemReader or to any generic ItemReader implementation). You need to prepare all necessary stuff (datasource, session, real database readers) and bind all delegated readers to your custom reader. EDIT: You … Read more

Spring batch jpaPagingItemReader why some rows are not read?

org.springframework.batch.item.database.JpaPagingItemReader creates is own entityManager instance (from org.springframework.batch.item.database.JpaPagingItemReader#doOpen) : entityManager = entityManagerFactory.createEntityManager(jpaPropertyMap); If you are within a transaction, as it seems to be, reader entities are not detached (from org.springframework.batch.item.database.JpaPagingItemReader#doReadPage): if (!transacted) { List<T> queryResult = query.getResultList(); for (T entity : queryResult) { entityManager.detach(entity); results.add(entity); }//end if } else { results.addAll(query.getResultList()); tx.commit(); } For this … Read more

Spring Batch ORA-08177: can’t serialize access for this transaction when running single job, SERIALIZED isolation level

From official doc – 4.3.1 The default isolation level for that method is SERIALIZABLE, which is quite aggressive: READ_COMMITTED would work just as well; READ_UNCOMMITTED would be fine if two processes are not likely to collide in this way. However, since a call to the create* method is quite short, it is unlikely that the … Read more