1

Just setup my first spring-boot-batch project using spring-data-jpa. I have a working solution in my dev environment, whereby I consume some rows from an Oracle DB in my itemReader, parse some xml/html out in my processor for each row, then write out each extracted html out to an individual file using a custom itemWriter. (1 file per row)

My datasource is configured via spring-data-jpa in the boot project (application.properties)...

I noticed OOTB spring-batch creates various schema objects for its jobRepository using the available datasource.

This is fine in a dev environment, but i only have "read" access in our production Oracle DB environment where my itemReader will be gettings its official data.

I tried configuring 2 datasources as outlined in the spring docs i came across.. but couldn't get it working. I also tried using in-memory instead, but couldn't get that working either.

So is this possible? Or should I keep plugging away at getting the in-memory job repo working?

I'm not too concerned with restartability at this point.. batch job will be run on my desktop as a standalone spring-boot application.

Any help, tips, information is greatly appreciated.

Update:

Trying the in-memory configuration, here is part of my batch config class:

 @Configuration @EnableBatchProcessing public class BatchConfiguration { private static final Logger log = LoggerFactory.getLogger(BatchConfiguration.class); @Autowired public JobBuilderFactory jobBuilderFactory; @Autowired public StepBuilderFactory stepBuilderFactory; @Autowired EntityManagerFactory emf; @Bean public SimpleJobLauncher jobLauncher(JobRepository jobRepository) { SimpleJobLauncher simpleJobLauncher = new SimpleJobLauncher(); simpleJobLauncher.setJobRepository(jobRepository); return simpleJobLauncher; } @Bean public JobRepository jobRepository(ResourcelessTransactionManager transactionManager) throws Exception { MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean = new MapJobRepositoryFactoryBean(transactionManager); mapJobRepositoryFactoryBean.setTransactionManager(transactionManager); return mapJobRepositoryFactoryBean.getObject(); } @Bean public ResourcelessTransactionManager transactionManager() { return new ResourcelessTransactionManager(); } 

Project compiles ok, but when i run, i get the following:

Caused by: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? order by JOB_INSTANCE_ID desc]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist

So seems its still trying to hook up to Oracle, and not use the in-memory DB..

1 Answer 1

1

well... seems this config has done the trick for my case.

@Configuration @EnableBatchProcessing public class BatchConfiguration { private static final Logger log = LoggerFactory.getLogger(BatchConfiguration.class); @Autowired public JobBuilderFactory jobBuilderFactory; @Autowired public StepBuilderFactory stepBuilderFactory; @Autowired EntityManagerFactory emf; @Bean public SimpleJobLauncher jobLauncher(JobRepository jobRepository) throws Exception { SimpleJobLauncher simpleJobLauncher = new SimpleJobLauncher(); simpleJobLauncher.setJobRepository(jobRepository); simpleJobLauncher.afterPropertiesSet(); return simpleJobLauncher; } @Bean public MapJobRepositoryFactoryBean mapJobRepositoryFactory(ResourcelessTransactionManager txManager) throws Exception { MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(txManager); factory.afterPropertiesSet(); return factory; } @Bean public JobRepository jobRepository(MapJobRepositoryFactoryBean factory) throws Exception { return factory.getObject(); } @Bean public ResourcelessTransactionManager resourcelessTransactionManager() { return new ResourcelessTransactionManager(); } @Bean public JobExplorer jobExplorer(MapJobRepositoryFactoryBean factory) { return new SimpleJobExplorer(factory.getJobInstanceDao(), factory.getJobExecutionDao(), factory.getStepExecutionDao(), factory.getExecutionContextDao()); } 
Sign up to request clarification or add additional context in comments.

1 Comment

In my answer to stackoverflow.com/questions/40553985/… I explained how to use different datasources. Please not that using the MapJobRepository for production ist NOT recommended by SpringBatch.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.