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 db172d9c5..23439e6eb 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 @@ -30,7 +30,7 @@ import org.springframework.context.annotation.ScopedProxyMode; * @Since 2.2 * */ -@Scope(value = "step", proxyMode = ScopedProxyMode.INTERFACES) +@Scope(value = "step", proxyMode = ScopedProxyMode.TARGET_CLASS) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface StepScope { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTests.java index 5c51a9321..95e244dba 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTests.java @@ -103,8 +103,18 @@ public class StepScopeConfigurationTests { } @Test - public void testStepScopeWithInterface() throws Exception { - init(StepScopeConfigurationWithInterface.class); + public void testIntentionallyBlowupWithForcedInterface() throws Exception { + init(StepScopeConfigurationForcingInterfaceProxy.class); + StepSynchronizationManager.release(); + expected.expect(BeanCreationException.class); + expected.expectMessage("step scope"); + SimpleHolder value = context.getBean(SimpleHolder.class); + assertEquals("STEP", value.call()); + } + + @Test + public void testStepScopeWithDefaults() throws Exception { + init(StepScopeConfigurationWithDefaults.class); @SuppressWarnings("unchecked") Callable value = context.getBean(Callable.class); assertEquals("STEP", value.call()); @@ -112,7 +122,7 @@ public class StepScopeConfigurationTests { @Test public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Exception { - init(StepScopeConfigurationWithInterface.class); + init(StepScopeConfigurationWithDefaults.class); StepSynchronizationManager.release(); expected.expect(BeanCreationException.class); expected.expectMessage("step scope"); @@ -222,7 +232,7 @@ public class StepScopeConfigurationTests { @Configuration @EnableBatchProcessing - public static class StepScopeConfigurationWithInterface { + public static class StepScopeConfigurationWithDefaults { @Bean @StepScope @@ -233,4 +243,17 @@ public class StepScopeConfigurationTests { } + @Configuration + @EnableBatchProcessing + public static class StepScopeConfigurationForcingInterfaceProxy { + + @Bean + @Scope(value="step", proxyMode = ScopedProxyMode.INTERFACES) + protected SimpleHolder value(@Value("#{stepExecution.stepName}") + final String value) { + return new SimpleHolder(value); + } + + } + }