BeanDefinitionVisitor/PropertyPlaceholderConfigurer finds and resolves values in arrays as well (SPR-7136)

master
Juergen Hoeller 15 years ago
parent dd8c18188f
commit 17a1362ed8
  1. 16
      org.springframework.beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java
  2. 8
      org.springframework.beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java

@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -183,6 +183,9 @@ public class BeanDefinitionVisitor {
return new RuntimeBeanNameReference(newBeanName);
}
}
else if (value instanceof Object[]) {
visitArray((Object[]) value);
}
else if (value instanceof List) {
visitList((List) value);
}
@ -206,6 +209,17 @@ public class BeanDefinitionVisitor {
return value;
}
@SuppressWarnings("unchecked")
protected void visitArray(Object[] arrayVal) {
for (int i = 0; i < arrayVal.length; i++) {
Object elem = arrayVal[i];
Object newVal = resolveValue(elem);
if (!ObjectUtils.nullSafeEquals(newVal, elem)) {
arrayVal[i] = newVal;
}
}
}
@SuppressWarnings("unchecked")
protected void visitList(List listVal) {
for (int i = 0; i < listVal.size(); i++) {

@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -376,6 +376,9 @@ public final class PropertyResourceConfigurerTests {
cas.addGenericArgumentValue("${var}name${age}");
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("stringArray", new String[] {"${os.name}", "${age}"});
List<Object> friends = new ManagedList<Object>();
friends.add("na${age}me");
friends.add(new RuntimeBeanReference("${ref}"));
@ -422,6 +425,9 @@ public final class PropertyResourceConfigurerTests {
assertEquals(tb2, tb1.getSpouse());
assertEquals(1, tb1.getSomeMap().size());
assertEquals("myValue", tb1.getSomeMap().get("myKey"));
assertEquals(2, tb2.getStringArray().length);
assertEquals(System.getProperty("os.name"), tb2.getStringArray()[0]);
assertEquals("98", tb2.getStringArray()[1]);
assertEquals(2, tb2.getFriends().size());
assertEquals("na98me", tb2.getFriends().iterator().next());
assertEquals(tb2, tb2.getFriends().toArray()[1]);

Loading…
Cancel
Save