Update 69.1. Execute Spring Batch jobs on startup.md

master
qibaoguang 2015-04-08 00:09:47 +08:00
parent 2b1d94f15e
commit 5724af016b
1 changed files with 10 additions and 0 deletions

View File

@ -0,0 +1,10 @@
### 69.1. 在启动时执行Spring Batch作业
你可以在上下文的某个地方添加`@EnableBatchProcessing`来启用Spring Batch的自动配置功能。
默认情况下在启动时它会执行应用的所有作业Jobs具体查看[JobLauncherCommandLineRunner](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherCommandLineRunner.java)。你可以通过指定`spring.batch.job.names`(多个作业名以逗号分割)来缩小到一个特定的作业或多个作业。
如果应用上下文包含一个JobRegistry那么处于`spring.batch.job.names`中的作业将会从registry中查找而不是从上下文中自动装配。这是复杂系统中常见的一个模式在这些系统中多个作业被定义在子上下文和注册中心。
具体参考[BatchAutoConfiguration](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.java)和[@EnableBatchProcessing](https://github.com/spring-projects/spring-batch/blob/master/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java)。