Skip to content

Commit 3780068

Browse files
author
Dave Syer
committed
BATCH-2023: Change default @StepScope proxy mode to INTERFACES
1 parent 3f1d56b commit 3780068

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/StepScope.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* @Since 2.2
3131
*
3232
*/
33-
@Scope(value = "step", proxyMode = ScopedProxyMode.INTERFACES)
33+
@Scope(value = "step", proxyMode = ScopedProxyMode.TARGET_CLASS)
3434
@Retention(RetentionPolicy.RUNTIME)
3535
@Documented
3636
public @interface StepScope {

spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTests.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,26 @@ public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws
103103
}
104104

105105
@Test
106-
public void testStepScopeWithInterface() throws Exception {
107-
init(StepScopeConfigurationWithInterface.class);
106+
public void testIntentionallyBlowupWithForcedInterface() throws Exception {
107+
init(StepScopeConfigurationForcingInterfaceProxy.class);
108+
StepSynchronizationManager.release();
109+
expected.expect(BeanCreationException.class);
110+
expected.expectMessage("step scope");
111+
SimpleHolder value = context.getBean(SimpleHolder.class);
112+
assertEquals("STEP", value.call());
113+
}
114+
115+
@Test
116+
public void testStepScopeWithDefaults() throws Exception {
117+
init(StepScopeConfigurationWithDefaults.class);
108118
@SuppressWarnings("unchecked")
109119
Callable<String> value = context.getBean(Callable.class);
110120
assertEquals("STEP", value.call());
111121
}
112122

113123
@Test
114124
public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Exception {
115-
init(StepScopeConfigurationWithInterface.class);
125+
init(StepScopeConfigurationWithDefaults.class);
116126
StepSynchronizationManager.release();
117127
expected.expect(BeanCreationException.class);
118128
expected.expectMessage("step scope");
@@ -222,7 +232,7 @@ protected SimpleHolder value(@Value("#{stepExecution.stepName}")
222232

223233
@Configuration
224234
@EnableBatchProcessing
225-
public static class StepScopeConfigurationWithInterface {
235+
public static class StepScopeConfigurationWithDefaults {
226236

227237
@Bean
228238
@StepScope
@@ -233,4 +243,17 @@ protected Callable<String> value(@Value("#{stepExecution.stepName}")
233243

234244
}
235245

246+
@Configuration
247+
@EnableBatchProcessing
248+
public static class StepScopeConfigurationForcingInterfaceProxy {
249+
250+
@Bean
251+
@Scope(value="step", proxyMode = ScopedProxyMode.INTERFACES)
252+
protected SimpleHolder value(@Value("#{stepExecution.stepName}")
253+
final String value) {
254+
return new SimpleHolder(value);
255+
}
256+
257+
}
258+
236259
}

0 commit comments

Comments
 (0)