spring - Spring批处理作业在应用程序启动时自动启动。如何避免身份证?
问题描述
我在 Spring 中做一个简单的项目来了解 Spring 批处理是如何工作的。我的项目工作,但是当应用程序启动时执行该工作,我不希望这样。有办法避免吗?
我已经能够在需要时启动任务(例如转到由@RestController 映射的某个 URL)。唯一的问题是批处理作业在应用程序启动时启动。
但是我的 Spring 批处理配置代码是:
@Configuration
@EnableBatchProcessing
public class BatchConfiguration {
@Autowired
public JobBuilderFactory jobBuilderFactory;
@Autowired
public StepBuilderFactory stepBuilderFactory;
@Bean
public FlatFileItemReader<Person> reader() {
return new FlatFileItemReaderBuilder<Person>()
.name("personItemReader")
.resource(new ClassPathResource("sample-data.csv"))
.delimited()
.names(new String[]{"firstName", "lastName"})
.fieldSetMapper(new BeanWrapperFieldSetMapper<Person>() {{
setTargetType(Person.class);
}})
.build();
}
@Bean
public PersonItemProcessor processor() {
return new PersonItemProcessor();
}
@Bean
public JdbcBatchItemWriter<Person> writer(DataSource dataSource) {
return new JdbcBatchItemWriterBuilder<Person>()
.itemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>())
.sql("INSERT INTO people (first_name, last_name) VALUES (:firstName, :lastName)")
.dataSource(dataSource)
.build();
}
@Bean
public Job importUserJob(JobCompletionNotificationListener listener, Step step1) {
return jobBuilderFactory.get("importUserJob")
.incrementer(new RunIdIncrementer())
.listener(listener)
.start(step1)
// .flow(step1)
// .end()
.build();
}
@Bean
public Step step1(JdbcBatchItemWriter<Person> writer) {
return stepBuilderFactory.get("step1")
.<Person, Person> chunk(10)
.reader(reader())
.processor(processor())
.writer(writer)
.build();
}
}
我有一个用于这个项目的 github 存储库: https ://github.com/Mazzotta13/SpringBatch.git
提前致谢。
解决方案
在你的 application.properties 添加这个
spring.batch.job.enabled=false
希望有用
推荐阅读
- json - 从 Wordpress API 获得不同的响应
- sql - 在 SQL 中循环使用日期
- python - 如何查看真正存储在内存中的 float 的二进制值。Python
- python - 如果失败,几天后重新运行 python 脚本
- jsonata - JSONata:如何替换 . 键名中有_?
- java - 与 Avro 模式的向后和向前兼容性
- c# - 使用任务和 task.delay 时 HttpListener 阻塞
- javascript - 使用 Select2 + Jquery 隐藏另一个 html 组件
- flutter - 从 Flutter 中的 SlideTransition 中删除白色背景
- macos - 如何像 Figma 一样自定义 Electron 红绿灯?