I tried spring.batch.job.enabled=false
in application.properties and -Dspring.batch.job.enabled=false
when running the jar file.
However
I was able to know whats going on, I am using custom reader/processor/writer. When springboot application starts it actually try to do dependency injection of this custom beans beans where I have written some application logic.
Example
** TestConfiguration.class**
@Configuration
@EnableBatchProcessing
public class TestConfiguration {
@Bean
@Conditional(Employee.class)
public ItemWriter writer_employee(DataSource dataSource) throws IOException {
FlatFileItemWriter writer = new FlatFileItemWriter();
writer.setResource(new FileSystemResource(FinanceReportUtil.createFile("Employee.csv")));
writer.setHeaderCallback(new FlatFileHeaderCallback() {
@Override
public void writeHeader(Writer writer) throws IOException {
writer.write("id, name");
}
});
DelimitedLineAggregator delLineAgg = new DelimitedLineAggregator();
delLineAgg.setDelimiter(",");
BeanWrapperFieldExtractor fieldExtractor = new BeanWrapperFieldExtractor();
fieldExtractor.setNames(new String[]{"id", "name"});
delLineAgg.setFieldExtractor(fieldExtractor);
writer.setLineAggregator(delLineAgg);
return writer;
}
@Bean
@Conditional(Manager.class)
public ItemWriter writer_manager(DataSource dataSource) throws IOException {
// Does the same logic as employee
}
// Also has job and step etc.
}
It will create the file even with spring.batch.job.enabled=false, to overcome this I have created custom logic to inject the beans or not as below
application.properties
# all, manager, employee
person=manager
ManagerCondition.class
public class ManagerCondition implements Condition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
String person= context.getEnvironment().getProperty("person");
return person.equals("manager");
}