This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,15 @@
|
||||
<property name="parent" value="#{stepExecutionContext[parent]}" />
|
||||
</bean>
|
||||
|
||||
<bean id="nested" class="org.springframework.batch.core.scope.TestCollaborator">
|
||||
<property name="name" value="foo" />
|
||||
<property name="parent">
|
||||
<bean class="org.springframework.batch.core.scope.TestCollaborator" scope="step">
|
||||
<property name="name" value="#{stepExecutionContext[foo]}" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="list" class="org.springframework.batch.core.scope.TestCollaborator" scope="step">
|
||||
<property name="name" value="foo" />
|
||||
<property name="list">
|
||||
|
||||
Reference in New Issue
Block a user