diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java index d8545cc3b..aaf15b2dc 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java @@ -21,67 +21,73 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.springframework.batch.core.configuration.JobRegistry; +import org.springframework.batch.core.configuration.support.ApplicationContextFactory; +import org.springframework.batch.core.configuration.support.AutomaticJobRegistrar; +import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobRepository; import org.springframework.context.annotation.Import; +import org.springframework.transaction.PlatformTransactionManager; /** *
* Enable Spring Batch features and provide a base configuration for setting up batch jobs in an @Configuration
* class, roughly equivalent to using the {@code
* @Configuration
* @EnableBatchProcessing
* @Import(DataSourceCnfiguration.class)
* public class AppConfig {
- *
+ *
* @Autowired
* private JobBuilderFactory jobs;
- *
+ *
* @Bean
* public Job job() {
* return jobs.get("myJob").start(step1()).next(step2()).build();
* }
- *
+ *
* @Bean
* protected Step step1() {
* ...
* }
- *
+ *
* @Bean
* protected Step step2() {
* ...
* }
* }
*
- *
+ *
* The user has to provide a {@link DataSource} as a bean in the context, or else implement {@link BatchConfigurer} in
* the configuration class itself, e.g.
- *
+ *
*
* @Configuration
* @EnableBatchProcessing
* public class AppConfig extends DefaultBatchConfigurer {
- *
+ *
* @Bean
* public Job job() {
* ...
* }
- *
+ *
* @Override
* protected JobRepository createJobRepository() {
* ...
* }
- *
+ *
* ...
- *
+ *
* }
*
- *
+ *
* Note that only one of your configuration classes needs to have the @EnableBatchProcessing
* annotation. Once you have an @EnableBatchProcessing class in your configuration you will have an
* instance of {@link StepScope} so your beans inside steps can have @Scope("step"). You will also be
* able to @Autowired some useful stuff into your context:
- *
+ *
*
*
- *
+ *
* If the configuration is specified as modular=true then the context will also contain an
* {@link AutomaticJobRegistrar}. The job registrar is useful for modularizing your configuration if there are multiple
* jobs. It works by creating separate child application contexts containing job configurations and registering those
* jobs. The jobs can then create steps and other dependent components without needing to worry about bean definition
* name clashes. Beans of type {@link ApplicationContextFactory} will be registered automatically with the job
* registrar. Example:
- *
+ *
*
* @Configuration
* @EnableBatchProcessing(modular=true)
* public class AppConfig {
- *
+ *
* @Bean
* public ApplicationContextFactory someJobs() {
* return new GenericApplicationContextFactory(SomeJobConfiguration.class);
* }
- *
+ *
* @Bean
* public ApplicationContextFactory moreJobs() {
* return new GenericApplicationContextFactory(MoreJobConfiguration.class);
* }
- *
+ *
* ...
- *
+ *
* }
*
- *
+ *
* Note that a modular parent context in general should not itself contain @Bean definitions for job,
* especially if a {@link BatchConfigurer} is provided, because cyclic configuration dependencies are otherwise likely
* to develop.
- *
+ *
*
* For reference, the first example above can be compared to the following Spring XML configuration: - * + * *
* {@code
*
@@ -144,9 +150,9 @@ import org.springframework.context.annotation.Import;
*
* }
*
- *
+ *
* @author Dave Syer
- *
+ *
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/StepScope.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/StepScope.java
index 20e348258..8ac7895b9 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/StepScope.java
+++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/StepScope.java
@@ -13,7 +13,7 @@ import org.springframework.context.annotation.ScopedProxyMode;
* explicitly on every bean definition. Use this on any @Bean that needs to inject @Values from the step
* context, and any bean that needs to share a lifecycle with a step execution (e.g. an ItemStream). E.g.
*
- *
+ *
* * @Bean * @StepScope @@ -22,13 +22,13 @@ import org.springframework.context.annotation.ScopedProxyMode; * return new SimpleCallable(value); * } *- * - *
Marking a @Bean as @StepScope is quivalent to marking it as @Scope(value="step", proxyMode=INTERFACES)
Marking a @Bean as @StepScope is equivalent to marking it as @Scope(value="step", proxyMode=INTERFACES)