BATCH-1847: Updated StepScope to not proxy abstract beans

This commit is contained in:
Michael Minella
2013-03-01 18:11:06 -06:00
parent 6dbf543309
commit b1bd3d3d1e
3 changed files with 30 additions and 6 deletions

View File

@@ -144,7 +144,6 @@ public class StepScope implements Scope, BeanFactoryPostProcessor, Ordered {
@SuppressWarnings("rawtypes")
@Override
public Object get(String name, ObjectFactory objectFactory) {
StepContext context = getContext();
Object scopedObject = context.getAttribute(name);
@@ -239,7 +238,8 @@ public class StepScope implements Scope, BeanFactoryPostProcessor, Ordered {
boolean scoped = name.equals(definition.getScope());
Scopifier scopifier = new Scopifier(registry, name, proxyTargetClass, scoped);
scopifier.visitBeanDefinition(definition);
if (scoped) {
if (scoped && !definition.isAbstract()) {
createScopedProxy(beanName, definition, registry, proxyTargetClass);
}
}

View File

@@ -69,6 +69,15 @@ public class StepScopeConfigurationTests {
assertEquals("STEP", value.call());
}
@Test
public void testXmlStepScopeWithInheritence() throws Exception {
context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTestsInheritence-context.xml");
StepSynchronizationManager.register(stepExecution);
SimpleHolder value = (SimpleHolder) context.getBean("child");
assertEquals("STEP", value.call());
}
@Test
public void testStepScopeWithProxyTargetClass() throws Exception {
init(StepScopeConfigurationRequiringProxyTargetClass.class);
@@ -165,7 +174,7 @@ public class StepScopeConfigurationTests {
return value;
}
}
public static class Wrapper {
private SimpleHolder value;
@@ -173,17 +182,17 @@ public class StepScopeConfigurationTests {
public Wrapper(SimpleHolder value) {
this.value = value;
}
public SimpleHolder getValue() {
return value;
}
}
@Configuration
@EnableBatchProcessing
public static class StepScopeConfigurationInjectingProxy {
@Bean
public Wrapper wrapper(SimpleHolder value) {
return new Wrapper(value);

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 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-3.1.xsd">
<bean class="org.springframework.batch.core.scope.StepScope">
<property name="proxyTargetClass" value="true" />
</bean>
<bean id="parent" class="org.springframework.batch.core.configuration.annotation.StepScopeConfigurationTests.SimpleHolder" scope="step" abstract="true">
<constructor-arg value="#{stepExecution.stepName}" />
</bean>
<bean id="child" class="org.springframework.batch.core.configuration.annotation.StepScopeConfigurationTests.SimpleHolder" parent="parent"/>
</beans>