diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java index df22acc2f4..065bd50254 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java @@ -78,6 +78,7 @@ import org.springframework.util.xml.DomUtils; * @author Juergen Hoeller * @author Rod Johnson * @author Mark Fisher + * @author Gary Russell * @since 2.0 * @see ParserContext * @see DefaultBeanDefinitionDocumentReader @@ -1302,13 +1303,24 @@ public class BeanDefinitionParserDelegate { Object value = null; boolean hasValueAttribute = entryEle.hasAttribute(VALUE_ATTRIBUTE); boolean hasValueRefAttribute = entryEle.hasAttribute(VALUE_REF_ATTRIBUTE); + boolean hasValueTypeAttribute = entryEle.hasAttribute(VALUE_TYPE_ATTRIBUTE); if ((hasValueAttribute && hasValueRefAttribute) || ((hasValueAttribute || hasValueRefAttribute)) && valueEle != null) { error(" element is only allowed to contain either " + "'value' attribute OR 'value-ref' attribute OR sub-element", entryEle); } + if ((hasValueTypeAttribute && hasValueRefAttribute) || + (hasValueTypeAttribute && !hasValueAttribute) || + (hasValueTypeAttribute && valueEle != null)) { + error(" element is only allowed to contain a 'value-type' " + + "attribute when it has a 'value' attribute", entryEle); + } if (hasValueAttribute) { - value = buildTypedStringValueForMap(entryEle.getAttribute(VALUE_ATTRIBUTE), defaultValueType, entryEle); + String valueType = entryEle.getAttribute(VALUE_TYPE_ATTRIBUTE); + if (!StringUtils.hasText(valueType)) { + valueType = defaultValueType; + } + value = buildTypedStringValueForMap(entryEle.getAttribute(VALUE_ATTRIBUTE), valueType, entryEle); } else if (hasValueRefAttribute) { String refName = entryEle.getAttribute(VALUE_REF_ATTRIBUTE); diff --git a/spring-beans/src/main/resources/org/springframework/beans/factory/xml/spring-beans-3.2.xsd b/spring-beans/src/main/resources/org/springframework/beans/factory/xml/spring-beans-3.2.xsd index c8dec32958..48194aeaa6 100644 --- a/spring-beans/src/main/resources/org/springframework/beans/factory/xml/spring-beans-3.2.xsd +++ b/spring-beans/src/main/resources/org/springframework/beans/factory/xml/spring-beans-3.2.xsd @@ -1153,6 +1153,14 @@ ]]> + + + ..." element. + ]]> + + diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlBeanCollectionTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlBeanCollectionTests.java index 00e3b20b95..460c18a9f6 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlBeanCollectionTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlBeanCollectionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2012 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. @@ -196,11 +196,15 @@ public class XmlBeanCollectionTests { @Test public void testMapWithLiteralsAndReferences() throws Exception { HasMap hasMap = (HasMap) this.beanFactory.getBean("mixedMap"); - assertTrue(hasMap.getMap().size() == 3); + assertTrue(hasMap.getMap().size() == 5); assertTrue(hasMap.getMap().get("foo").equals(new Integer(10))); TestBean jenny = (TestBean) this.beanFactory.getBean("jenny"); assertTrue(hasMap.getMap().get("jenny") == jenny); assertTrue(hasMap.getMap().get(new Integer(5)).equals("david")); + assertTrue(hasMap.getMap().get("bar") instanceof Long); + assertTrue(hasMap.getMap().get("bar").equals(new Long(100))); + assertTrue(hasMap.getMap().get("baz") instanceof Integer); + assertTrue(hasMap.getMap().get("baz").equals(new Integer(200))); } @Test diff --git a/spring-beans/src/test/resources/org/springframework/beans/factory/xml/collections.xml b/spring-beans/src/test/resources/org/springframework/beans/factory/xml/collections.xml index 9d772d3fd5..44bd0b92dc 100644 --- a/spring-beans/src/test/resources/org/springframework/beans/factory/xml/collections.xml +++ b/spring-beans/src/test/resources/org/springframework/beans/factory/xml/collections.xml @@ -1,7 +1,7 @@ + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"> Jenny @@ -133,7 +133,7 @@ - + 10 @@ -151,6 +151,8 @@ + +