Since Spring Batch uses DB-based Job repository by default, a table for Job management is created without permission. If you are a DB user who does not have the authority to create a table, or if you are concerned about performance, you can use the In-Memory Job repository. However, in the case of In-Memory Job repository, functions such as restart will not be available, so whether to use it depends on non-functional requirements.
Note that the in-memory repository is volatile and so does not allow restart between JVM instances. It also cannot guarantee that two job instances with the same parameters are launched simultaneously, and is not suitable for use in a multi-threaded Job, or a locally partitioned Step. So use the database version of the repository wherever you need those features.
The easiest solution is not to use the DataSource's AutoConfig.
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args).close();
}
}
Spring Batch 3.0.8.RLEASE API Description of Annotation Type Enable Batch Processing
If a user does not provide a DataSource within the context, a Map based JobRepository will be used.
Even if the DataSource is AutoConfig, you can use the Map-based JobRepository by overriding JobRepository, JobExplorer, and JobLauncher.
@Configuration
@EnableBatchProcessing
public class BatchConfig {
......
/**
* in-use memory job repository
*
* @return
*/
@Bean
DefaultBatchConfigurer batchConfigurer() {
return new DefaultBatchConfigurer() {
private JobRepository jobRepository;
private JobExplorer jobExplorer;
private JobLauncher jobLauncher;
{
MapJobRepositoryFactoryBean jobRepositoryFactory = new MapJobRepositoryFactoryBean();
try {
this.jobRepository = jobRepositoryFactory.getObject();
MapJobExplorerFactoryBean jobExplorerFactory = new MapJobExplorerFactoryBean(jobRepositoryFactory);
this.jobExplorer = jobExplorerFactory.getObject();
SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
jobLauncher.setJobRepository(jobRepository);
jobLauncher.afterPropertiesSet();
this.jobLauncher = jobLauncher;
} catch (Exception e) {
}
}
@Override
public JobRepository getJobRepository() {
return jobRepository;
}
@Override
public JobExplorer getJobExplorer() {
return jobExplorer;
}
@Override
public JobLauncher getJobLauncher() {
return jobLauncher;
}
};
}
}
Modify ʻapplication.properties` as follows to prevent the metadata table from being generated.
application.properties
spring.batch.initializer.enabled=false
Reference: https://blog.ik.am/entries/409 https://qiita.com/blackawa/items/e9eaa254cbe27e257e10
Recommended Posts