From 17a1362ed898c51af002241b64c799c3b017f85f Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 3 May 2010 12:26:32 +0000 Subject: [PATCH] BeanDefinitionVisitor/PropertyPlaceholderConfigurer finds and resolves values in arrays as well (SPR-7136) --- .../factory/config/BeanDefinitionVisitor.java | 16 +++++++++++++++- .../config/PropertyResourceConfigurerTests.java | 8 +++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java index d5b5617cca..eb49eb7b02 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.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++) { diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java index a47c0c8c13..d4e59c3875 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java +++ b/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. @@ -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 friends = new ManagedList(); 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]);