diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/StepScope.java b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/StepScope.java index 0defafd86..0b4cf7c55 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/StepScope.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/StepScope.java @@ -104,6 +104,10 @@ public class StepScope implements Scope, BeanFactoryPostProcessor, Ordered { private boolean proxyTargetClass = false; + private static boolean springThreeDetected; + + private static boolean cachedSpringThreeResult; + /** * Flag to indicate that proxies should use dynamic subclassing. This allows * classes with no interface to be proxied. Defaults to false. @@ -229,7 +233,12 @@ public class StepScope implements Scope, BeanFactoryPostProcessor, Ordered { } private static boolean isSpringThree() { - return ReflectionUtils.findMethod(Scope.class, "resolveContextualObject", new Class[] { String.class }) != null; + if (!cachedSpringThreeResult) { + springThreeDetected = ReflectionUtils.findMethod(Scope.class, "resolveContextualObject", + new Class[] { String.class }) != null; + cachedSpringThreeResult = true; + } + return springThreeDetected; } /** @@ -326,7 +335,9 @@ public class StepScope implements Scope, BeanFactoryPostProcessor, Ordered { if (definition != null) { boolean nestedScoped = scope.equals(definition.getScope()); boolean scopeChangeRequiresProxy = !scoped && nestedScoped; - new ExpressionHider(scope, nestedScoped).visitBeanDefinition(definition); + if (!isSpringThree()) { + new ExpressionHider(scope, nestedScoped).visitBeanDefinition(definition); + } if (scopeChangeRequiresProxy) { // Exit here so that nested inner bean definitions are not // analysed diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/scope/StepScopePlaceholderIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/scope/StepScopePlaceholderIntegrationTests.java index 0f60ebd44..b710b869e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/scope/StepScopePlaceholderIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/scope/StepScopePlaceholderIntegrationTests.java @@ -47,6 +47,10 @@ public class StepScopePlaceholderIntegrationTests implements BeanFactoryAware { @Qualifier("bar") private Collaborator bar; + @Autowired + @Qualifier("nested") + private Collaborator nested; + private StepExecution stepExecution; private ListableBeanFactory beanFactory; @@ -128,4 +132,9 @@ public class StepScopePlaceholderIntegrationTests implements BeanFactoryAware { assertEquals("[bar]", list.getList().toString()); } + @Test + public void testNested() throws Exception { + assertEquals("bar", nested.getParent().getName()); + } + } diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/scope/StepScopePlaceholderIntegrationTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/scope/StepScopePlaceholderIntegrationTests-context.xml index bfa813628..d7e7d6b8c 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/scope/StepScopePlaceholderIntegrationTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/scope/StepScopePlaceholderIntegrationTests-context.xml @@ -19,6 +19,15 @@ + + + + + + + + +