From 8f8600c14d9fdc4dd671cd03d9d49fe27bb3c6ed Mon Sep 17 00:00:00 2001 From: Michael Minella Date: Thu, 12 Jun 2014 16:42:48 -0500 Subject: [PATCH] BATCH-2253: Added automatic registraiton of Job Scope to java config and added support for a @JobScope annotation. --- .../AbstractBatchConfiguration.java | 14 +- .../annotation/EnableBatchProcessing.java | 3 +- .../configuration/annotation/JobScope.java | 53 ++++ .../JobScopeConfigurationTests.java | 261 ++++++++++++++++++ .../xml/AutoRegisteringStepScopeTests.java | 8 +- ...eConfigurationTestsInheritence-context.xml | 15 + ...opeConfigurationTestsInterface-context.xml | 12 + ...igurationTestsProxyTargetClass-context.xml | 13 + 8 files changed, 371 insertions(+), 8 deletions(-) create mode 100644 spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/JobScope.java create mode 100644 spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTests.java create mode 100644 spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTestsInheritence-context.xml create mode 100644 spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTestsInterface-context.xml create mode 100644 spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTestsProxyTargetClass-context.xml diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AbstractBatchConfiguration.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AbstractBatchConfiguration.java index 32d09dac2..bd51bef4f 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AbstractBatchConfiguration.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AbstractBatchConfiguration.java @@ -20,7 +20,6 @@ import org.springframework.batch.core.configuration.support.MapJobRegistry; import org.springframework.batch.core.explore.JobExplorer; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.scope.StepScope; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; @@ -31,6 +30,8 @@ import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.type.AnnotationMetadata; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.util.Assert; +import org.springframework.batch.core.scope.JobScope; +import org.springframework.batch.core.scope.StepScope; import javax.sql.DataSource; import java.util.Collection; @@ -44,7 +45,7 @@ import java.util.Collection; * @see EnableBatchProcessing */ @Configuration -@Import(StepScopeConfiguration.class) +@Import(ScopeConfiguration.class) public abstract class AbstractBatchConfiguration implements ImportAware { @Autowired @@ -129,14 +130,21 @@ public abstract class AbstractBatchConfiguration implements ImportAware { * */ @Configuration -class StepScopeConfiguration { +class ScopeConfiguration { private StepScope stepScope = new StepScope(); + private JobScope jobScope = new JobScope(); + @Bean public StepScope stepScope() { stepScope.setAutoProxy(false); return stepScope; } + @Bean + public JobScope jobScope() { + jobScope.setAutoProxy(false); + return jobScope; + } } \ No newline at end of file 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 cedf8cc83..5dea5f600 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 @@ -89,7 +89,8 @@ import java.lang.annotation.Target; * * 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 + * instance of {@link StepScope} and {@link org.springframework.batch.core.scope.JobScope} so your beans inside steps + * can have @Scope("step") and @Scope("job") respectively. You will also be * able to @Autowired some useful stuff into your context: * *