Spring Batch uses a database to store the state of jobs and so on.
It's usually convenient, but it's a little annoying when it's not such a heavy batch.
It is a method that does not use or make such a table.
This article was very helpful. : smile: Do this when Spring Batch does not want to use metatable but it is used
The table is created while Spring Boot automatically configures it.
You can do it well.
But this time it is omitted.
Add the following settings to your properties file or yaml file.
application.properties
spring.batch.initializer.enabled=false
Please read this article. Do this when Spring Batch does not want to use metatable but it is used
Alternatively, you may create your own BatchConfigurer class (I created it because I made a detour).
MyBatchConfigurer.java
import javax.annotation.PostConstruct;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.configuration.BatchConfigurationException;
import org.springframework.batch.core.configuration.annotation.BatchConfigurer;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.launch.support.SimpleJobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;
/**
*Use Job Repository without database
*
*/
@Component
public class MyBatchConfigurer implements BatchConfigurer {
private static final Log LOG = LogFactory.getLog(MyBatchConfigurer.class);
private PlatformTransactionManager transactionManager;
private JobRepository jobRepository;
private JobLauncher jobLauncher;
private JobExplorer jobExplorer;
@PostConstruct
public void initialize() {
if (this.transactionManager == null) {
LOG.info("Create ResourceLessTransactionManager.");
this.transactionManager = new ResourcelessTransactionManager();
}
try {
MapJobRepositoryFactoryBean repoFactory
= new MapJobRepositoryFactoryBean(this.transactionManager);
repoFactory.afterPropertiesSet();
this.jobRepository = repoFactory.getObject();
MapJobExplorerFactoryBean explFactory
= new MapJobExplorerFactoryBean(repoFactory);
explFactory.afterPropertiesSet();
this.jobExplorer = explFactory.getObject();
this.jobLauncher = createJobLauncher();
} catch (Exception ex) {
LOG.fatal(ex.getMessage(), ex);
throw new BatchConfigurationException(ex);
}
}
protected JobLauncher createJobLauncher() throws Exception {
SimpleJobLauncher launcher = new SimpleJobLauncher();
launcher.setJobRepository(jobRepository);
launcher.afterPropertiesSet();
return launcher;
}
@Override
public JobRepository getJobRepository() throws Exception {
return jobRepository;
}
@Override
public PlatformTransactionManager getTransactionManager() throws Exception {
return transactionManager;
}
@Override
public JobLauncher getJobLauncher() throws Exception {
return jobLauncher;
}
@Override
public JobExplorer getJobExplorer() throws Exception {
return jobExplorer;
}
}
When I disabled it, there were various classes that I had to create, so I enabled it.
I prepared Batch Configurer by myself, so it seems OK.
Recommended Posts