How to get JobParameter and JobExecutionContext in the ItemWriter?

Implementing StepExecutionListener is one way. In fact that’s the only way in Spring Batch 1.x. Starting from Spring Batch 2, you have another choice: You can inject whatever entries in Job Parameters and Job Execution Context to your item writer. Make your item writer with step scope, then make use of expression like #{jobParameters[‘theKeyYouWant’]} or … Read more

Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException

The error comes from JpaTransactionManager line 403: TransactionSynchronizationManager.bindResource(getDataSource(), conHolder); The error means that the transaction manager is trying to bind the datasource (not the entity manager) to the thread, but the datasource is already there and this is unexpected. Note that the transaction manager had not started yet to bind the Entity Manager to the … 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

Spring Batch: org.springframework.batch.item.ReaderNotOpenException: Reader must be open before it can be read

The issue disappeared when I change the return type of my reader bean from Item to FlatFileItemReader. It is still not clear to me why this is a problem since chunk().reader() accepts ItemReader as an input. I assume that there is some AOP magic under the hood which does FlatFileReader init and matches by the … 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

Difference between Step, Tasklet and Chunk in Spring Batch [closed]

Well that’s actually a good question. Here’s an example of configuration: <job id=”sampleJob” job-repository=”jobRepository”> <step id=”step1″ next=”step2″> <tasklet transaction-manager=”transactionManager”> <chunk reader=”itemReader” writer=”itemWriter” commit-interval=”10″/> </tasklet> </step> <step id=”step2″> <tasklet ref=”myTasklet”/> </step> </job> You have a Job, this job is made of steps. Most of the time, these steps are successive. You define in what order your … 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

javax.management.InstanceNotFoundException: org.springframework.boot:type=Admin,name=SpringApplication

I had the same issue with IDEA IntelliJ. The problem was IntelliJ’s default server configurations. You just need to remove the ‘Enable launch optimization’ and ‘Enable JMX agent’ checkboxes, then it works! Steps: Edit Configurations choose your project remove the ‘Enable launch optimization’ and ‘Enable JMX agent’ checkboxes

Advantages of spring batch [closed]

Let me rephrase your question a bit and see if this addresses it. What does Spring Batch provide that I’d have to handle myself when building a batch application? Spring Batch served as the basis for JSR-352 (the java batch specification) and since that specification has come out, there is a lot of Spring Batch … Read more