BATCH-1126: Invalid
This commit is contained in:
@@ -273,6 +273,7 @@ public class StepScope implements Scope, BeanFactoryPostProcessor, Ordered {
|
||||
BeanDefinition definition = (BeanDefinition) value;
|
||||
if (scope.equals(definition.getScope())) {
|
||||
String beanName = BeanDefinitionReaderUtils.generateBeanName(definition, registry);
|
||||
// Exit here so that nested inner bean definitions are not analysed
|
||||
return createScopedProxy(beanName, definition, registry, proxyTargetClass);
|
||||
}
|
||||
}
|
||||
@@ -280,9 +281,11 @@ public class StepScope implements Scope, BeanFactoryPostProcessor, Ordered {
|
||||
BeanDefinitionHolder holder = (BeanDefinitionHolder) value;
|
||||
BeanDefinition definition = holder.getBeanDefinition();
|
||||
if (scope.equals(definition.getScope())) {
|
||||
// Exit here so that nested inner bean definitions are not analysed
|
||||
return createScopedProxy(holder.getBeanName(), definition, registry, proxyTargetClass);
|
||||
}
|
||||
}
|
||||
// Nested inner bean definitions are recursively analysed here
|
||||
value = super.resolveValue(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -19,19 +19,22 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class StepScopeIntegrationTests {
|
||||
|
||||
|
||||
@Autowired
|
||||
@Qualifier("vanilla")
|
||||
private Step vanilla;
|
||||
|
||||
|
||||
@Autowired
|
||||
@Qualifier("proxied")
|
||||
private Step proxied;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("nested")
|
||||
private Step nested;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("enhanced")
|
||||
private Step enhanced;
|
||||
@@ -46,31 +49,47 @@ public class StepScopeIntegrationTests {
|
||||
StepSynchronizationManager.close();
|
||||
TestStep.reset();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testScopeCreation() throws Exception {
|
||||
vanilla.execute(new StepExecution("foo",new JobExecution(11L),12L));
|
||||
vanilla.execute(new StepExecution("foo", new JobExecution(11L), 12L));
|
||||
assertNotNull(TestStep.getContext());
|
||||
assertNull(StepSynchronizationManager.getContext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScopedProxy() throws Exception {
|
||||
proxied.execute(new StepExecution("foo",new JobExecution(11L),31L));
|
||||
assertTrue(TestStep.getContext().attributeNames().length>0);
|
||||
proxied.execute(new StepExecution("foo", new JobExecution(11L), 31L));
|
||||
assertTrue(TestStep.getContext().attributeNames().length > 0);
|
||||
String collaborator = (String) TestStep.getContext().getAttribute("collaborator");
|
||||
assertNotNull(collaborator);
|
||||
assertEquals("bar", collaborator);
|
||||
assertTrue("Scoped proxy not created", ((String) TestStep.getContext().getAttribute("collaborator.class"))
|
||||
.startsWith("class $Proxy"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedScopedProxy() throws Exception {
|
||||
nested.execute(new StepExecution("foo", new JobExecution(11L), 31L));
|
||||
assertTrue(TestStep.getContext().attributeNames().length > 0);
|
||||
String collaborator = (String) TestStep.getContext().getAttribute("collaborator");
|
||||
assertNotNull(collaborator);
|
||||
assertEquals("foo", collaborator);
|
||||
String parent = (String) TestStep.getContext().getAttribute("parent");
|
||||
assertNotNull(parent);
|
||||
assertEquals("bar", parent);
|
||||
assertTrue("Scoped proxy not created", ((String) TestStep.getContext().getAttribute("parent.class"))
|
||||
.startsWith("class $Proxy"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecutionContext() throws Exception {
|
||||
StepExecution stepExecution = new StepExecution("foo",new JobExecution(11L), 1L);
|
||||
StepExecution stepExecution = new StepExecution("foo", new JobExecution(11L), 1L);
|
||||
ExecutionContext executionContext = new ExecutionContext();
|
||||
executionContext.put("name", "spam");
|
||||
stepExecution.setExecutionContext(executionContext);
|
||||
proxied.execute(stepExecution);
|
||||
assertTrue(TestStep.getContext().attributeNames().length>0);
|
||||
assertTrue(TestStep.getContext().attributeNames().length > 0);
|
||||
String collaborator = (String) TestStep.getContext().getAttribute("collaborator");
|
||||
assertNotNull(collaborator);
|
||||
assertEquals("bar", collaborator);
|
||||
@@ -78,8 +97,8 @@ public class StepScopeIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testScopedProxyForReference() throws Exception {
|
||||
enhanced.execute(new StepExecution("foo",new JobExecution(11L),123L));
|
||||
assertTrue(TestStep.getContext().attributeNames().length>0);
|
||||
enhanced.execute(new StepExecution("foo", new JobExecution(11L), 123L));
|
||||
assertTrue(TestStep.getContext().attributeNames().length > 0);
|
||||
String collaborator = (String) TestStep.getContext().getAttribute("collaborator");
|
||||
assertNotNull(collaborator);
|
||||
assertEquals("bar", collaborator);
|
||||
@@ -87,8 +106,8 @@ public class StepScopeIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testScopedProxyForSecondReference() throws Exception {
|
||||
doubleEnhanced.execute(new StepExecution("foo",new JobExecution(11L),321L));
|
||||
assertTrue(TestStep.getContext().attributeNames().length>0);
|
||||
doubleEnhanced.execute(new StepExecution("foo", new JobExecution(11L), 321L));
|
||||
assertTrue(TestStep.getContext().attributeNames().length > 0);
|
||||
String collaborator = (String) TestStep.getContext().getAttribute("collaborator");
|
||||
assertNotNull(collaborator);
|
||||
assertEquals("bar", collaborator);
|
||||
|
||||
@@ -33,8 +33,12 @@ public class TestStep implements Step {
|
||||
|
||||
private void setContextFromCollaborator() {
|
||||
if (context != null) {
|
||||
String name = collaborator.getName();
|
||||
context.setAttribute("collaborator", name);
|
||||
context.setAttribute("collaborator", collaborator.getName());
|
||||
context.setAttribute("collaborator.class", collaborator.getClass().toString());
|
||||
if (collaborator.getParent()!=null) {
|
||||
context.setAttribute("parent", collaborator.getParent().getName());
|
||||
context.setAttribute("parent.class", collaborator.getParent().getClass().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
|
||||
@@ -17,13 +16,25 @@
|
||||
|
||||
<bean id="proxied" class="org.springframework.batch.core.scope.TestStep">
|
||||
<property name="collaborator">
|
||||
<bean class="org.springframework.batch.core.scope.TestCollaborator"
|
||||
scope="step">
|
||||
<bean class="org.springframework.batch.core.scope.TestCollaborator" scope="step">
|
||||
<property name="name" value="bar" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="nested" class="org.springframework.batch.core.scope.TestStep">
|
||||
<property name="collaborator">
|
||||
<bean 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="bar" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="enhanced" class="org.springframework.batch.core.scope.TestStep">
|
||||
<property name="collaborator" ref="collaborator" />
|
||||
</bean>
|
||||
@@ -32,8 +43,7 @@
|
||||
<property name="collaborator" ref="collaborator" />
|
||||
</bean>
|
||||
|
||||
<bean id="collaborator" class="org.springframework.batch.core.scope.TestCollaborator"
|
||||
scope="step">
|
||||
<bean id="collaborator" class="org.springframework.batch.core.scope.TestCollaborator" scope="step">
|
||||
<property name="name" value="bar" />
|
||||
</bean>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user