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 Framework – Auto create Batch Table

UPDATE: As of spring 2.5.0, you should use spring.batch.jdbc.initialize-schema instead. See source. With Spring Boot 2.0 you probably need this: https://docs.spring.io/spring-boot/docs/2.0.0.M7/reference/htmlsingle/#howto-initialize-a-spring-batch-database spring.batch.initialize-schema=always By default it will only create the tables if you are using an embedded database. Or spring.batch.initialize-schema=never To permanently disable it.

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 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 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

How to java-configure separate datasources for spring batch data and business data? Should I even do it?

Ok, this is strange but it works. Moving the datasources to it’s own configuration class works just fine and one is able to autowire. The example is a multi-datasource version of Spring Batch Service Example: DataSourceConfiguration: public class DataSourceConfiguration { @Value(“classpath:schema-mysql.sql”) private Resource schemaScript; @Bean @Primary public DataSource hsqldbDataSource() throws SQLException { final SimpleDriverDataSource dataSource … Read more

Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured

Just add : @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class }) works for me. I was getting same error I tried with @EnableAutoConfiguration(exclude=…) didn’t work. For those that are wondering where to add @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class }), as it has been asked by user as well. You need to add it to the main Application class which is under … Read more