I have a Spring Boot application using JPA that has 1 PostgreSQL database. And I am using Spring Batch. The scenario is I am reading a file and writing data to the PostgreSQL database. The program works with PostgreSQL when it is creating meta-data tables used by Spring Batch in the database. But what I need is Spring Boot not to create meta-data tables and use in-memory Map-based job repository by Spring Batch. I don't want to create meta-data tables in the database at all. Need to just execute in-memory Map-based. I tried many answers but none of them worked. And I see,
MapJobRepositoryFactoryBean is deprecated
Here is my BatchConfiguration.java class,
@Configuration
@EnableBatchProcessing
public class BatchConfiguration {
private @Autowired JobBuilderFactory jobBuilderFactory;
private @Autowired StepBuilderFactory stepBuilderFactory;
private @Autowired UserItemReader userItemReader;
private @Autowired UserItemProcessor userItemProcessor;
private @Autowired UserItemWriter userItemWriter;
@Bean
public Step importUsersStep() {
return stepBuilderFactory.get("STEP-01")
.<User, User>chunk(10)
.reader(userItemReader)
.processor(userItemProcessor)
.writer(userItemWriter)
.build();
}
@Bean
public Job importUsersJob() {
return jobBuilderFactory.get("JOB-IMPORT")
.flow(importUsersStep())
.end()
.build();
}
}
Repository.java class,
public interface UserRepository extends JpaRepository<User, Long> {
}
And in UserItemWriter.java in write method I am calling userRepository.saveAll();
So how can I make this to work with in-memory Map-based and also since I am using Spring Data JPA to save the user to the database so the save should also work without any issue because when I am trying some approaches I saw nothing committed to PostgreSQL and I think even the user data also committed to in-memory Map. So anybody can help me? Thanks in advance.
DataSourceTransactionManagerif you provide a datasource in your context. But if you use JPA, you need to configure Spring Batch to use aJpaTransactionManagerinstead.