RESOLVED - issue BATCH-1420: Late Binding only happens first time when using inner bean definition with collection property
This commit is contained in:
@@ -30,6 +30,8 @@ import org.springframework.beans.PropertyEditorRegistrySupport;
|
||||
import org.springframework.beans.TypeConverter;
|
||||
import org.springframework.beans.TypeMismatchException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionVisitor;
|
||||
import org.springframework.beans.factory.config.TypedStringValue;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
@@ -266,7 +268,7 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
|
||||
|
||||
private Object getPropertyFromContext(String key) {
|
||||
Object context = contextFactory.getContext();
|
||||
if (context==null) {
|
||||
if (context == null) {
|
||||
throw new IllegalStateException("No context available while replacing placeholders.");
|
||||
}
|
||||
BeanWrapper wrapper = new BeanWrapperImpl(context);
|
||||
@@ -334,30 +336,47 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
|
||||
}
|
||||
}
|
||||
|
||||
} else if (value instanceof Map) {
|
||||
|
||||
}
|
||||
else if (value instanceof Map) {
|
||||
|
||||
Map map = (Map) value;
|
||||
Map newValue = new ManagedMap(map.size());
|
||||
newValue.putAll(map);
|
||||
super.visitMap(newValue);
|
||||
value = newValue;
|
||||
|
||||
} else if (value instanceof List) {
|
||||
|
||||
|
||||
}
|
||||
else if (value instanceof List) {
|
||||
|
||||
List list = (List) value;
|
||||
List newValue = new ManagedList(list.size());
|
||||
newValue.addAll(list);
|
||||
super.visitList(newValue);
|
||||
value = newValue;
|
||||
|
||||
} else if (value instanceof Set) {
|
||||
|
||||
|
||||
}
|
||||
else if (value instanceof Set) {
|
||||
|
||||
Set list = (Set) value;
|
||||
Set newValue = new ManagedSet(list.size());
|
||||
newValue.addAll(list);
|
||||
super.visitSet(newValue);
|
||||
value = newValue;
|
||||
|
||||
|
||||
}
|
||||
else if (value instanceof BeanDefinition) {
|
||||
|
||||
BeanDefinition newValue = new GenericBeanDefinition((BeanDefinition) value);
|
||||
visitBeanDefinition((BeanDefinition) newValue);
|
||||
value = newValue;
|
||||
|
||||
}
|
||||
else if (value instanceof BeanDefinitionHolder) {
|
||||
|
||||
BeanDefinition newValue = new GenericBeanDefinition(((BeanDefinitionHolder) value).getBeanDefinition());
|
||||
visitBeanDefinition((BeanDefinition) newValue);
|
||||
value = newValue;
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import static org.junit.Assert.fail;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -26,6 +27,8 @@ public class TaskExecutorPartitionHandlerTests {
|
||||
private TaskExecutorPartitionHandler handler = new TaskExecutorPartitionHandler();
|
||||
|
||||
private int count = 0;
|
||||
|
||||
private Collection<String> stepExecutions = new TreeSet<String>();
|
||||
|
||||
private StepExecution stepExecution = new StepExecution("step", new JobExecution(1L));
|
||||
|
||||
@@ -50,6 +53,7 @@ public class TaskExecutorPartitionHandlerTests {
|
||||
@Override
|
||||
public void execute(StepExecution stepExecution) throws JobInterruptedException {
|
||||
count++;
|
||||
stepExecutions.add(stepExecution.getStepName());
|
||||
}
|
||||
});
|
||||
handler.afterPropertiesSet();
|
||||
@@ -74,6 +78,7 @@ public class TaskExecutorPartitionHandlerTests {
|
||||
handler.setGridSize(2);
|
||||
handler.handle(stepExecutionSplitter, stepExecution);
|
||||
assertEquals(2, count);
|
||||
assertEquals("[foo0, foo1]", stepExecutions.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -61,6 +61,10 @@ public class MultipleContextPlaceholderTargetSourceTests {
|
||||
@Qualifier("list")
|
||||
private TestBean list;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("nestedList")
|
||||
private TestBean nestedList;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("map")
|
||||
private TestBean map;
|
||||
@@ -120,6 +124,23 @@ public class MultipleContextPlaceholderTargetSourceTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleValueInNestedList() throws Exception {
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
final String value = "foo" + i;
|
||||
contextFactory.setContext(this);
|
||||
attributes = Collections.singletonMap("foo", value);
|
||||
try {
|
||||
assertEquals("foo" + i, nestedList.getParent().getNames().get(0));
|
||||
}
|
||||
finally {
|
||||
contextFactory.clearContext();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleValueInMap() throws Exception {
|
||||
|
||||
@@ -144,10 +165,20 @@ public class MultipleContextPlaceholderTargetSourceTests {
|
||||
|
||||
public static class TestBean {
|
||||
private String name;
|
||||
|
||||
private TestBean parent;
|
||||
|
||||
private List<String> names = new ArrayList<String>();
|
||||
|
||||
private Map<String, String> map = new HashMap<String, String>();
|
||||
|
||||
public TestBean getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(TestBean parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
|
||||
@@ -36,6 +36,16 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="nestedList" class="org.springframework.aop.framework.ProxyFactoryBean">
|
||||
<property name="targetSource">
|
||||
<bean
|
||||
class="org.springframework.batch.core.scope.util.PlaceholderTargetSource">
|
||||
<property name="contextFactory" ref="context" />
|
||||
<property name="targetBeanName" value="nestedListTarget" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="map" class="org.springframework.aop.framework.ProxyFactoryBean">
|
||||
<property name="targetSource">
|
||||
<bean
|
||||
@@ -60,7 +70,22 @@
|
||||
class="org.springframework.batch.core.scope.util.MultipleContextPlaceholderTargetSourceTests$TestBean">
|
||||
<property name="names">
|
||||
<list>
|
||||
<value>%{attributes[foo]}</value></list>
|
||||
<value>%{attributes[foo]}</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="nestedListTarget"
|
||||
class="org.springframework.batch.core.scope.util.MultipleContextPlaceholderTargetSourceTests$TestBean">
|
||||
<property name="parent">
|
||||
<bean
|
||||
class="org.springframework.batch.core.scope.util.MultipleContextPlaceholderTargetSourceTests$TestBean">
|
||||
<property name="names">
|
||||
<list>
|
||||
<value>%{attributes[foo]}</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user