spring_reference/IX. ‘How-to’ guides/69.1. Execute Spring Batch ...

11 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### 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)。