storing type information as specified (SPR-5556, SPR-5562); explicit XML array element in spring-beans-3.0.xsd (SPR-5543)
This commit is contained in:
@@ -1,60 +1,90 @@
|
||||
/*
|
||||
* Copyright 2002-2009 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans.factory.xml;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import test.beans.TestBean;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class CollectionsWithDefaultTypesTests extends TestCase {
|
||||
public class CollectionsWithDefaultTypesTests {
|
||||
|
||||
private XmlBeanFactory beanFactory;
|
||||
private final XmlBeanFactory beanFactory;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
public CollectionsWithDefaultTypesTests() {
|
||||
this.beanFactory = new XmlBeanFactory(new ClassPathResource("collectionsWithDefaultTypes.xml", getClass()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListHasDefaultType() throws Exception {
|
||||
TestBean bean = (TestBean) this.beanFactory.getBean("testBean");
|
||||
List list = bean.getSomeList();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Object o = list.get(i);
|
||||
for (Object o : bean.getSomeList()) {
|
||||
assertEquals("Value type is incorrect", Integer.class, o.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetHasDefaultType() throws Exception {
|
||||
TestBean bean = (TestBean) this.beanFactory.getBean("testBean");
|
||||
Set set = bean.getSomeSet();
|
||||
Iterator iterator = set.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Object o = iterator.next();
|
||||
for (Object o : bean.getSomeSet()) {
|
||||
assertEquals("Value type is incorrect", Integer.class, o.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapHasDefaultKeyAndValueType() throws Exception {
|
||||
TestBean bean = (TestBean) this.beanFactory.getBean("testBean");
|
||||
assertMap(bean.getSomeMap());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapWithNestedElementsHasDefaultKeyAndValueType() throws Exception {
|
||||
TestBean bean = (TestBean) this.beanFactory.getBean("testBean2");
|
||||
assertMap(bean.getSomeMap());
|
||||
}
|
||||
|
||||
private void assertMap(Map map) {
|
||||
for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) iterator.next();
|
||||
private void assertMap(Map<?,?> map) {
|
||||
for (Map.Entry entry : map.entrySet()) {
|
||||
assertEquals("Key type is incorrect", Integer.class, entry.getKey().getClass());
|
||||
assertEquals("Value type is incorrect", Boolean.class, entry.getValue().getClass());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildCollectionFromMixtureOfReferencesAndValues() throws Exception {
|
||||
MixedCollectionBean jumble = (MixedCollectionBean) this.beanFactory.getBean("jumble");
|
||||
assertTrue("Expected 3 elements, not " + jumble.getJumble().size(),
|
||||
jumble.getJumble().size() == 3);
|
||||
List l = (List) jumble.getJumble();
|
||||
assertTrue(l.get(0).equals("literal"));
|
||||
Integer[] array1 = (Integer[]) l.get(1);
|
||||
assertTrue(array1[0].equals(new Integer(2)));
|
||||
assertTrue(array1[1].equals(new Integer(4)));
|
||||
int[] array2 = (int[]) l.get(2);
|
||||
assertTrue(array2[0] == 3);
|
||||
assertTrue(array2[1] == 5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.beans.factory.xml;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -30,7 +28,10 @@ import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import test.beans.TestBean;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.config.ListFactoryBean;
|
||||
@@ -38,8 +39,6 @@ import org.springframework.beans.factory.config.MapFactoryBean;
|
||||
import org.springframework.beans.factory.config.SetFactoryBean;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import test.beans.TestBean;
|
||||
|
||||
/**
|
||||
* Tests for collections in XML bean definitions.
|
||||
*
|
||||
@@ -49,6 +48,12 @@ import test.beans.TestBean;
|
||||
*/
|
||||
public class XmlBeanCollectionTests {
|
||||
|
||||
private final XmlBeanFactory beanFactory;
|
||||
|
||||
public XmlBeanCollectionTests() {
|
||||
this.beanFactory = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollectionFactoryDefaults() throws Exception {
|
||||
ListFactoryBean listFactory = new ListFactoryBean();
|
||||
@@ -69,40 +74,35 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testRefSubelement() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
//assertTrue("5 beans in reftypes, not " + xbf.getBeanDefinitionCount(), xbf.getBeanDefinitionCount() == 5);
|
||||
TestBean jen = (TestBean) xbf.getBean("jenny");
|
||||
TestBean dave = (TestBean) xbf.getBean("david");
|
||||
//assertTrue("5 beans in reftypes, not " + this.beanFactory.getBeanDefinitionCount(), this.beanFactory.getBeanDefinitionCount() == 5);
|
||||
TestBean jen = (TestBean) this.beanFactory.getBean("jenny");
|
||||
TestBean dave = (TestBean) this.beanFactory.getBean("david");
|
||||
assertTrue(jen.getSpouse() == dave);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyWithLiteralValueSubelement() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
TestBean verbose = (TestBean) xbf.getBean("verbose");
|
||||
TestBean verbose = (TestBean) this.beanFactory.getBean("verbose");
|
||||
assertTrue(verbose.getName().equals("verbose"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyWithIdRefLocalAttrSubelement() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
TestBean verbose = (TestBean) xbf.getBean("verbose2");
|
||||
TestBean verbose = (TestBean) this.beanFactory.getBean("verbose2");
|
||||
assertTrue(verbose.getName().equals("verbose"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyWithIdRefBeanAttrSubelement() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
TestBean verbose = (TestBean) xbf.getBean("verbose3");
|
||||
TestBean verbose = (TestBean) this.beanFactory.getBean("verbose3");
|
||||
assertTrue(verbose.getName().equals("verbose"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefSubelementsBuildCollection() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
TestBean jen = (TestBean) xbf.getBean("jenny");
|
||||
TestBean dave = (TestBean) xbf.getBean("david");
|
||||
TestBean rod = (TestBean) xbf.getBean("rod");
|
||||
TestBean jen = (TestBean) this.beanFactory.getBean("jenny");
|
||||
TestBean dave = (TestBean) this.beanFactory.getBean("david");
|
||||
TestBean rod = (TestBean) this.beanFactory.getBean("rod");
|
||||
|
||||
// Must be a list to support ordering
|
||||
// Our bean doesn't modify the collection:
|
||||
@@ -117,11 +117,9 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testRefSubelementsBuildCollectionWithPrototypes() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
|
||||
TestBean jen = (TestBean) xbf.getBean("pJenny");
|
||||
TestBean dave = (TestBean) xbf.getBean("pDavid");
|
||||
TestBean rod = (TestBean) xbf.getBean("pRod");
|
||||
TestBean jen = (TestBean) this.beanFactory.getBean("pJenny");
|
||||
TestBean dave = (TestBean) this.beanFactory.getBean("pDavid");
|
||||
TestBean rod = (TestBean) this.beanFactory.getBean("pRod");
|
||||
Object[] friends = rod.getFriends().toArray();
|
||||
assertTrue(friends.length == 2);
|
||||
assertTrue("First friend must be jen, not " + friends[0],
|
||||
@@ -130,7 +128,7 @@ public class XmlBeanCollectionTests {
|
||||
assertTrue(friends[1].toString().equals(dave.toString()));
|
||||
assertTrue("Dave not same instance", friends[1] != dave);
|
||||
|
||||
TestBean rod2 = (TestBean) xbf.getBean("pRod");
|
||||
TestBean rod2 = (TestBean) this.beanFactory.getBean("pRod");
|
||||
Object[] friends2 = rod2.getFriends().toArray();
|
||||
assertTrue(friends2.length == 2);
|
||||
assertTrue("First friend must be jen, not " + friends2[0],
|
||||
@@ -142,50 +140,48 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testRefSubelementsBuildCollectionFromSingleElement() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
TestBean loner = (TestBean) xbf.getBean("loner");
|
||||
TestBean dave = (TestBean) xbf.getBean("david");
|
||||
TestBean loner = (TestBean) this.beanFactory.getBean("loner");
|
||||
TestBean dave = (TestBean) this.beanFactory.getBean("david");
|
||||
assertTrue(loner.getFriends().size() == 1);
|
||||
assertTrue(loner.getFriends().contains(dave));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildCollectionFromMixtureOfReferencesAndValues() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
MixedCollectionBean jumble = (MixedCollectionBean) xbf.getBean("jumble");
|
||||
assertTrue("Expected 4 elements, not " + jumble.getJumble().size(),
|
||||
jumble.getJumble().size() == 4);
|
||||
MixedCollectionBean jumble = (MixedCollectionBean) this.beanFactory.getBean("jumble");
|
||||
assertTrue("Expected 5 elements, not " + jumble.getJumble().size(),
|
||||
jumble.getJumble().size() == 5);
|
||||
List l = (List) jumble.getJumble();
|
||||
assertTrue(l.get(0).equals(xbf.getBean("david")));
|
||||
assertTrue(l.get(0).equals(this.beanFactory.getBean("david")));
|
||||
assertTrue(l.get(1).equals("literal"));
|
||||
assertTrue(l.get(2).equals(xbf.getBean("jenny")));
|
||||
assertTrue(l.get(2).equals(this.beanFactory.getBean("jenny")));
|
||||
assertTrue(l.get(3).equals("rod"));
|
||||
Object[] array = (Object[]) l.get(4);
|
||||
assertTrue(array[0].equals(this.beanFactory.getBean("david")));
|
||||
assertTrue(array[1].equals("literal2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidBeanNameReference() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
try {
|
||||
xbf.getBean("jumble2");
|
||||
this.beanFactory.getBean("jumble2");
|
||||
fail("Should have thrown BeanCreationException");
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
assertTrue(ex.getCause() instanceof BeanDefinitionStoreException);
|
||||
assertTrue(ex.getCause().getMessage().indexOf("rod2") != -1);
|
||||
assertTrue(ex.getCause().getMessage().contains("rod2"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyMap() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("emptyMap");
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("emptyMap");
|
||||
assertTrue(hasMap.getMap().size() == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapWithLiteralsOnly() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("literalMap");
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("literalMap");
|
||||
assertTrue(hasMap.getMap().size() == 3);
|
||||
assertTrue(hasMap.getMap().get("foo").equals("bar"));
|
||||
assertTrue(hasMap.getMap().get("fi").equals("fum"));
|
||||
@@ -194,27 +190,24 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testMapWithLiteralsAndReferences() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("mixedMap");
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("mixedMap");
|
||||
assertTrue(hasMap.getMap().size() == 3);
|
||||
assertTrue(hasMap.getMap().get("foo").equals(new Integer(10)));
|
||||
TestBean jenny = (TestBean) xbf.getBean("jenny");
|
||||
TestBean jenny = (TestBean) this.beanFactory.getBean("jenny");
|
||||
assertTrue(hasMap.getMap().get("jenny") == jenny);
|
||||
assertTrue(hasMap.getMap().get(new Integer(5)).equals("david"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapWithLiteralsAndPrototypeReferences() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
|
||||
TestBean jenny = (TestBean) xbf.getBean("pJenny");
|
||||
HasMap hasMap = (HasMap) xbf.getBean("pMixedMap");
|
||||
TestBean jenny = (TestBean) this.beanFactory.getBean("pJenny");
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("pMixedMap");
|
||||
assertTrue(hasMap.getMap().size() == 2);
|
||||
assertTrue(hasMap.getMap().get("foo").equals("bar"));
|
||||
assertTrue(hasMap.getMap().get("jenny").toString().equals(jenny.toString()));
|
||||
assertTrue("Not same instance", hasMap.getMap().get("jenny") != jenny);
|
||||
|
||||
HasMap hasMap2 = (HasMap) xbf.getBean("pMixedMap");
|
||||
HasMap hasMap2 = (HasMap) this.beanFactory.getBean("pMixedMap");
|
||||
assertTrue(hasMap2.getMap().size() == 2);
|
||||
assertTrue(hasMap2.getMap().get("foo").equals("bar"));
|
||||
assertTrue(hasMap2.getMap().get("jenny").toString().equals(jenny.toString()));
|
||||
@@ -223,11 +216,10 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testMapWithLiteralsReferencesAndList() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("mixedMapWithList");
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("mixedMapWithList");
|
||||
assertTrue(hasMap.getMap().size() == 4);
|
||||
assertTrue(hasMap.getMap().get(null).equals("bar"));
|
||||
TestBean jenny = (TestBean) xbf.getBean("jenny");
|
||||
TestBean jenny = (TestBean) this.beanFactory.getBean("jenny");
|
||||
assertTrue(hasMap.getMap().get("jenny").equals(jenny));
|
||||
|
||||
// Check list
|
||||
@@ -263,18 +255,16 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testEmptySet() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("emptySet");
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("emptySet");
|
||||
assertTrue(hasMap.getSet().size() == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPopulatedSet() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("set");
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("set");
|
||||
assertTrue(hasMap.getSet().size() == 3);
|
||||
assertTrue(hasMap.getSet().contains("bar"));
|
||||
TestBean jenny = (TestBean) xbf.getBean("jenny");
|
||||
TestBean jenny = (TestBean) this.beanFactory.getBean("jenny");
|
||||
assertTrue(hasMap.getSet().contains(jenny));
|
||||
assertTrue(hasMap.getSet().contains(null));
|
||||
Iterator it = hasMap.getSet().iterator();
|
||||
@@ -285,16 +275,14 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testEmptyProps() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("emptyProps");
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("emptyProps");
|
||||
assertTrue(hasMap.getProps().size() == 0);
|
||||
assertEquals(hasMap.getProps().getClass(), Properties.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPopulatedProps() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("props");
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("props");
|
||||
assertTrue(hasMap.getProps().size() == 2);
|
||||
assertTrue(hasMap.getProps().get("foo").equals("bar"));
|
||||
assertTrue(hasMap.getProps().get("2").equals("TWO"));
|
||||
@@ -302,17 +290,15 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testObjectArray() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("objectArray");
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("objectArray");
|
||||
assertTrue(hasMap.getObjectArray().length == 2);
|
||||
assertTrue(hasMap.getObjectArray()[0].equals("one"));
|
||||
assertTrue(hasMap.getObjectArray()[1].equals(xbf.getBean("jenny")));
|
||||
assertTrue(hasMap.getObjectArray()[1].equals(this.beanFactory.getBean("jenny")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassArray() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("classArray");
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("classArray");
|
||||
assertTrue(hasMap.getClassArray().length == 2);
|
||||
assertTrue(hasMap.getClassArray()[0].equals(String.class));
|
||||
assertTrue(hasMap.getClassArray()[1].equals(Exception.class));
|
||||
@@ -320,8 +306,7 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testIntegerArray() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("integerArray");
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("integerArray");
|
||||
assertTrue(hasMap.getIntegerArray().length == 3);
|
||||
assertTrue(hasMap.getIntegerArray()[0].intValue() == 0);
|
||||
assertTrue(hasMap.getIntegerArray()[1].intValue() == 1);
|
||||
@@ -330,14 +315,12 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testProps() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
|
||||
HasMap hasMap = (HasMap) xbf.getBean("props");
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("props");
|
||||
assertEquals(2, hasMap.getProps().size());
|
||||
assertEquals("bar", hasMap.getProps().getProperty("foo"));
|
||||
assertEquals("TWO", hasMap.getProps().getProperty("2"));
|
||||
|
||||
HasMap hasMap2 = (HasMap) xbf.getBean("propsViaMap");
|
||||
HasMap hasMap2 = (HasMap) this.beanFactory.getBean("propsViaMap");
|
||||
assertEquals(2, hasMap2.getProps().size());
|
||||
assertEquals("bar", hasMap2.getProps().getProperty("foo"));
|
||||
assertEquals("TWO", hasMap2.getProps().getProperty("2"));
|
||||
@@ -345,8 +328,7 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testListFactory() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
List list = (List) xbf.getBean("listFactory");
|
||||
List list = (List) this.beanFactory.getBean("listFactory");
|
||||
assertTrue(list instanceof LinkedList);
|
||||
assertTrue(list.size() == 2);
|
||||
assertEquals("bar", list.get(0));
|
||||
@@ -355,8 +337,7 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testPrototypeListFactory() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
List list = (List) xbf.getBean("pListFactory");
|
||||
List list = (List) this.beanFactory.getBean("pListFactory");
|
||||
assertTrue(list instanceof LinkedList);
|
||||
assertTrue(list.size() == 2);
|
||||
assertEquals("bar", list.get(0));
|
||||
@@ -365,8 +346,7 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testSetFactory() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
Set set = (Set) xbf.getBean("setFactory");
|
||||
Set set = (Set) this.beanFactory.getBean("setFactory");
|
||||
assertTrue(set instanceof TreeSet);
|
||||
assertTrue(set.size() == 2);
|
||||
assertTrue(set.contains("bar"));
|
||||
@@ -375,8 +355,7 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testPrototypeSetFactory() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
Set set = (Set) xbf.getBean("pSetFactory");
|
||||
Set set = (Set) this.beanFactory.getBean("pSetFactory");
|
||||
assertTrue(set instanceof TreeSet);
|
||||
assertTrue(set.size() == 2);
|
||||
assertTrue(set.contains("bar"));
|
||||
@@ -385,8 +364,7 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testMapFactory() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
Map map = (Map) xbf.getBean("mapFactory");
|
||||
Map map = (Map) this.beanFactory.getBean("mapFactory");
|
||||
assertTrue(map instanceof TreeMap);
|
||||
assertTrue(map.size() == 2);
|
||||
assertEquals("bar", map.get("foo"));
|
||||
@@ -395,8 +373,7 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testPrototypeMapFactory() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
Map map = (Map) xbf.getBean("pMapFactory");
|
||||
Map map = (Map) this.beanFactory.getBean("pMapFactory");
|
||||
assertTrue(map instanceof TreeMap);
|
||||
assertTrue(map.size() == 2);
|
||||
assertEquals("bar", map.get("foo"));
|
||||
@@ -405,8 +382,7 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testChoiceBetweenSetAndMap() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
MapAndSet sam = (MapAndSet) xbf.getBean("setAndMap");
|
||||
MapAndSet sam = (MapAndSet) this.beanFactory.getBean("setAndMap");
|
||||
assertTrue("Didn't choose constructor with Map argument", sam.getObject() instanceof Map);
|
||||
Map map = (Map) sam.getObject();
|
||||
assertEquals(3, map.size());
|
||||
@@ -417,8 +393,7 @@ public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testEnumSetFactory() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
Set set = (Set) xbf.getBean("enumSetFactory");
|
||||
Set set = (Set) this.beanFactory.getBean("enumSetFactory");
|
||||
assertTrue(set.size() == 2);
|
||||
assertTrue(set.contains("ONE"));
|
||||
assertTrue(set.contains("TWO"));
|
||||
@@ -516,4 +491,3 @@ class HasMap {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,376 +0,0 @@
|
||||
<?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-2.5.xsd">
|
||||
|
||||
<bean id="jenny" class="test.beans.TestBean">
|
||||
<property name="name"><value>Jenny</value></property>
|
||||
<property name="age"><value>30</value></property>
|
||||
<property name="spouse">
|
||||
<!-- Could use id and href -->
|
||||
<ref local="david"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="david" class="test.beans.TestBean">
|
||||
<description>
|
||||
Simple bean, without any collections.
|
||||
</description>
|
||||
<property name="name">
|
||||
<description>The name of the user</description>
|
||||
<value>David</value>
|
||||
</property>
|
||||
<property name="age"><value>27</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="rod" class="test.beans.TestBean">
|
||||
<property name="name"><value>Rod</value></property>
|
||||
<property name="age"><value>32</value></property>
|
||||
<property name="friends">
|
||||
<description>List of Rod's friends</description>
|
||||
<list>
|
||||
<ref local="jenny"/>
|
||||
<ref local="david"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="pJenny" class="test.beans.TestBean" scope="prototype">
|
||||
<property name="name"><value>Jenny</value></property>
|
||||
<property name="age"><value>30</value></property>
|
||||
<property name="spouse">
|
||||
<!-- Could use id and href -->
|
||||
<ref local="david"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="pDavid" class="test.beans.TestBean" scope="prototype">
|
||||
<property name="name"><value>David</value></property>
|
||||
<property name="age"><value>27</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="pRod" class="test.beans.TestBean" scope="prototype">
|
||||
<property name="name"><value>Rod</value></property>
|
||||
<property name="age"><value>32</value></property>
|
||||
<property name="friends">
|
||||
<list>
|
||||
<ref local="pJenny"/>
|
||||
<ref local="pDavid"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!--
|
||||
Try setting a collection property to a single value
|
||||
-->
|
||||
<bean id="loner" class="test.beans.TestBean">
|
||||
<property name="name"><value>loner</value></property>
|
||||
<property name="age"><value>26</value></property>
|
||||
<property name="friends">
|
||||
<list>
|
||||
<description>My List</description>
|
||||
<ref local="david"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="jumble" class="org.springframework.beans.factory.xml.MixedCollectionBean">
|
||||
<property name="jumble">
|
||||
<list>
|
||||
<ref local="david"/>
|
||||
<value>literal</value>
|
||||
<ref local="jenny"/>
|
||||
<idref local="rod"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="jumble2" class="org.springframework.beans.factory.xml.MixedCollectionBean" lazy-init="true">
|
||||
<property name="jumble">
|
||||
<list>
|
||||
<ref local="david"/>
|
||||
<value>literal</value>
|
||||
<ref local="jenny"/>
|
||||
<idref bean="rod"/>
|
||||
<idref bean="rod2"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="verbose" class="test.beans.TestBean">
|
||||
<property name="name"><value>verbose</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="verbose2" class="test.beans.TestBean">
|
||||
<property name="name"><idref local="verbose"/></property>
|
||||
</bean>
|
||||
|
||||
<bean id="verbose3" class="test.beans.TestBean">
|
||||
<property name="name"><idref bean="verbose"/></property>
|
||||
</bean>
|
||||
|
||||
<bean id="emptyMap" class="org.springframework.beans.factory.xml.HasMap">
|
||||
<property name="map">
|
||||
<map>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="literalMap" class="org.springframework.beans.factory.xml.HasMap">
|
||||
<property name="map">
|
||||
<map>
|
||||
<entry key="foo" value="bar"/>
|
||||
<entry key="fi" value="fum"/>
|
||||
<entry key="fa"><null/></entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="mixedMap" class="org.springframework.beans.factory.xml.HasMap">
|
||||
<property name="map">
|
||||
<map>
|
||||
<entry key-ref="fooKey">
|
||||
<value type="java.lang.Integer">10</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>
|
||||
<ref bean="jennyKey"/>
|
||||
</key>
|
||||
<ref local="jenny"/>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>
|
||||
<bean class="java.lang.Integer">
|
||||
<constructor-arg value="5"/>
|
||||
</bean>
|
||||
</key>
|
||||
<idref bean="david"/>
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="fooKey" class="java.lang.String">
|
||||
<constructor-arg value="foo"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jennyKey" class="java.lang.String">
|
||||
<constructor-arg value="jenny"/>
|
||||
</bean>
|
||||
|
||||
<bean id="pMixedMap" class="org.springframework.beans.factory.xml.HasMap" scope="prototype">
|
||||
<property name="map">
|
||||
<map>
|
||||
<entry key="foo" value="bar"/>
|
||||
<entry key="jenny" value-ref="pJenny"/>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="mixedMapWithList" class="org.springframework.beans.factory.xml.HasMap">
|
||||
<property name="map">
|
||||
<map>
|
||||
<entry>
|
||||
<key><null/></key>
|
||||
<value>bar</value>
|
||||
</entry>
|
||||
<entry key="jenny"><ref local="jenny"/></entry>
|
||||
<entry key="list">
|
||||
<list>
|
||||
<value>zero</value>
|
||||
<map>
|
||||
<entry key="fo"><value>bar</value></entry>
|
||||
<entry key="jen"><ref local="jenny"/></entry>
|
||||
</map>
|
||||
<list>
|
||||
<ref local="jenny"/>
|
||||
<value>ba</value>
|
||||
</list>
|
||||
<null/>
|
||||
</list>
|
||||
</entry>
|
||||
<entry key="map">
|
||||
<map>
|
||||
<entry key="foo"><value>bar</value></entry>
|
||||
<entry key="jenny"><ref local="jenny"/></entry>
|
||||
</map>
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="emptySet" class="org.springframework.beans.factory.xml.HasMap">
|
||||
<property name="set">
|
||||
<set>
|
||||
</set>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="set" class="org.springframework.beans.factory.xml.HasMap">
|
||||
<property name="set">
|
||||
<set>
|
||||
<value>bar</value>
|
||||
<ref local="jenny"/>
|
||||
<null/>
|
||||
</set>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="emptyProps" class="org.springframework.beans.factory.xml.HasMap">
|
||||
<property name="props">
|
||||
<props>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="props" class="org.springframework.beans.factory.xml.HasMap">
|
||||
<property name="props">
|
||||
<props>
|
||||
<prop key="foo">bar</prop>
|
||||
<prop key="2">TWO</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="propsViaMap" class="org.springframework.beans.factory.xml.HasMap">
|
||||
<property name="props">
|
||||
<map>
|
||||
<entry key="foo" value="bar"/>
|
||||
<entry key="2" value="TWO"/>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="objectArray" class="org.springframework.beans.factory.xml.HasMap">
|
||||
<property name="objectArray">
|
||||
<list>
|
||||
<value>one</value>
|
||||
<ref local="jenny"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="classArray" class="org.springframework.beans.factory.xml.HasMap">
|
||||
<property name="classArray">
|
||||
<list>
|
||||
<value>java.lang.String</value>
|
||||
<value>java.lang.Exception</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="integerArray" class="org.springframework.beans.factory.xml.HasMap">
|
||||
<property name="integerArray">
|
||||
<list>
|
||||
<value>0</value>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="listFactory" class="org.springframework.beans.factory.config.ListFactoryBean">
|
||||
<property name="sourceList">
|
||||
<list>
|
||||
<value>bar</value>
|
||||
<value>jenny</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="targetListClass">
|
||||
<value>java.util.LinkedList</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="pListFactory" class="org.springframework.beans.factory.config.ListFactoryBean">
|
||||
<property name="sourceList">
|
||||
<list>
|
||||
<value>bar</value>
|
||||
<value>jenny</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="targetListClass">
|
||||
<value>java.util.LinkedList</value>
|
||||
</property>
|
||||
<property name="singleton">
|
||||
<value>true</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="setFactory" class="org.springframework.beans.factory.config.SetFactoryBean">
|
||||
<property name="sourceSet">
|
||||
<set>
|
||||
<value>bar</value>
|
||||
<value>jenny</value>
|
||||
</set>
|
||||
</property>
|
||||
<property name="targetSetClass">
|
||||
<value>java.util.TreeSet</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="pSetFactory" class="org.springframework.beans.factory.config.SetFactoryBean">
|
||||
<property name="sourceSet">
|
||||
<set>
|
||||
<value>bar</value>
|
||||
<value>jenny</value>
|
||||
</set>
|
||||
</property>
|
||||
<property name="targetSetClass">
|
||||
<value>java.util.TreeSet</value>
|
||||
</property>
|
||||
<property name="singleton">
|
||||
<value>true</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="mapFactory" class="org.springframework.beans.factory.config.MapFactoryBean">
|
||||
<property name="sourceMap">
|
||||
<map>
|
||||
<entry key="foo"><value>bar</value></entry>
|
||||
<entry key="jen"><value>jenny</value></entry>
|
||||
</map>
|
||||
</property>
|
||||
<property name="targetMapClass">
|
||||
<value>java.util.TreeMap</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="pMapFactory" class="org.springframework.beans.factory.config.MapFactoryBean">
|
||||
<property name="sourceMap">
|
||||
<map>
|
||||
<entry key="foo"><value>bar</value></entry>
|
||||
<entry key="jen"><value>jenny</value></entry>
|
||||
</map>
|
||||
</property>
|
||||
<property name="targetMapClass">
|
||||
<value>java.util.TreeMap</value>
|
||||
</property>
|
||||
<property name="singleton">
|
||||
<value>true</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="setAndMap" class="org.springframework.beans.factory.xml.XmlBeanCollectionTests$MapAndSet">
|
||||
<constructor-arg>
|
||||
<map>
|
||||
<description>My Map</description>
|
||||
<entry key="key1" value="val1"/>
|
||||
<entry key="key2" value="val2"/>
|
||||
<entry key="key3" value="val3"/>
|
||||
</map>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="enumSetFactory" class="org.springframework.beans.factory.config.SetFactoryBean">
|
||||
<property name="sourceSet">
|
||||
<set>
|
||||
<description>My Set</description>
|
||||
<value type="java.lang.String">ONE</value>
|
||||
<value type="java.lang.String">TWO</value>
|
||||
</set>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,149 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<bean id="default" class="org.springframework.beans.factory.xml.FactoryMethods"
|
||||
factory-method="defaultInstance">
|
||||
<!-- No constructor-arg elements -->
|
||||
<property name="stringValue"><value>setterString</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="defaultTestBean" factory-bean="default" factory-method="getTestBean"
|
||||
init-method="haveBirthday" destroy-method="destroy"/>
|
||||
|
||||
<bean id="defaultTestBeanWithInvalidDestroyMethod" factory-bean="default" factory-method="getTestBean"
|
||||
init-method="haveBirthday" destroy-method="xxx" lazy-init="true"/>
|
||||
|
||||
<bean id="defaultTestBean.protected" factory-bean="default" factory-method="protectedGetTestBean"
|
||||
init-method="haveBirthday" destroy-method="destroy"/>
|
||||
|
||||
<bean id="defaultTestBean.private" factory-bean="default" factory-method="privateGetTestBean"
|
||||
init-method="haveBirthday" destroy-method="destroy"/>
|
||||
|
||||
<bean id="testBeanOnly" class="org.springframework.beans.factory.xml.FactoryMethods"
|
||||
factory-method="newInstance">
|
||||
<constructor-arg><ref local="juergen"/></constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="null" class="org.springframework.beans.factory.xml.FactoryMethods"
|
||||
factory-method="nullInstance"/>
|
||||
|
||||
<bean id="nullWithProperty" class="org.springframework.beans.factory.xml.FactoryMethods"
|
||||
factory-method="nullInstance" init-method="getName" scope="prototype">
|
||||
<property name="stringValue"><value>setterString</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="full" class="org.springframework.beans.factory.xml.FactoryMethods"
|
||||
factory-method="newInstance">
|
||||
<constructor-arg index="0"><ref local="juergen"/></constructor-arg>
|
||||
<constructor-arg index="1"><value>27</value></constructor-arg>
|
||||
<constructor-arg index="2"><value>gotcha</value></constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="fullWithNull" class="org.springframework.beans.factory.xml.FactoryMethods"
|
||||
factory-method="newInstance">
|
||||
<constructor-arg index="0"><ref local="juergen"/></constructor-arg>
|
||||
<constructor-arg index="1"><value>27</value></constructor-arg>
|
||||
<constructor-arg index="2" type="java.lang.Integer"><null/></constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="fullWithGenericNull" class="org.springframework.beans.factory.xml.FactoryMethods"
|
||||
factory-method="newInstance">
|
||||
<constructor-arg><ref local="juergen"/></constructor-arg>
|
||||
<constructor-arg type="int"><value>27</value></constructor-arg>
|
||||
<constructor-arg type="java.lang.Integer"><null/></constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="fullWithAutowire" class="org.springframework.beans.factory.xml.FactoryMethods"
|
||||
factory-method="newInstance" autowire="constructor">
|
||||
<constructor-arg index="0" ref="juergen"/>
|
||||
<constructor-arg index="1" value="27"/>
|
||||
</bean>
|
||||
|
||||
<bean id="stringToBeAutowired" class="java.lang.String">
|
||||
<constructor-arg value="gotchaAutowired"/>
|
||||
</bean>
|
||||
|
||||
<bean id="defaultPrototype" class="org.springframework.beans.factory.xml.FactoryMethods"
|
||||
scope="prototype" factory-method="defaultInstance">
|
||||
<!-- No constructor-arg elements -->
|
||||
<property name="stringValue"><value>setterString</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="testBeanOnlyPrototype" class="org.springframework.beans.factory.xml.FactoryMethods"
|
||||
factory-method="newInstance" scope="prototype">
|
||||
<constructor-arg><ref local="juergen"/></constructor-arg>
|
||||
<property name="stringValue"><value>testBeanOnlyPrototypeDISetterString</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="fullPrototype" class="org.springframework.beans.factory.xml.FactoryMethods"
|
||||
factory-method="newInstance" scope="prototype">
|
||||
<constructor-arg type="int"><value>27</value></constructor-arg>
|
||||
<constructor-arg><value>gotcha</value></constructor-arg>
|
||||
<constructor-arg><ref local="juergen"/></constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="noMatchPrototype" class="org.springframework.beans.factory.xml.FactoryMethods"
|
||||
factory-method="newInstance" scope="prototype">
|
||||
<constructor-arg index="0"><ref local="juergen"/></constructor-arg>
|
||||
<constructor-arg index="1"><value>27</value></constructor-arg>
|
||||
<constructor-arg index="2"><value>gotcha</value></constructor-arg>
|
||||
<constructor-arg index="3"><value>bogus</value></constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="listInstance" class="org.springframework.beans.factory.xml.FactoryMethods"
|
||||
factory-method="listInstance"/>
|
||||
|
||||
<bean id="juergen" class="test.beans.TestBean">
|
||||
<property name="name"><value>Juergen</value></property>
|
||||
</bean>
|
||||
|
||||
<!--
|
||||
The class is the factory class, not the created class.
|
||||
-->
|
||||
<bean id="externalFactoryMethodWithoutArgs"
|
||||
class="org.springframework.beans.factory.xml.TestBeanCreator"
|
||||
factory-method="createTestBean">
|
||||
</bean>
|
||||
|
||||
<bean id="externalFactoryMethodWithArgs" class="org.springframework.beans.factory.xml.TestBeanCreator"
|
||||
factory-method="createTestBean">
|
||||
<constructor-arg index="0"><value>Rod</value></constructor-arg>
|
||||
<constructor-arg><value type="java.lang.Integer">33</value></constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="instanceFactoryMethodWithoutArgs"
|
||||
factory-bean="instanceFactory"
|
||||
factory-method="defaultInstance"/>
|
||||
|
||||
<!-- Unnamed bean with factory-bean declaration -->
|
||||
<bean factory-bean="instanceFactory" factory-method="defaultInstance"/>
|
||||
|
||||
<bean id="testBeanWithInnerFactoryMethod" class="test.beans.TestBean">
|
||||
<property name="friends">
|
||||
<list>
|
||||
<!-- Unnamed bean with factory-bean declaration -->
|
||||
<bean factory-bean="instanceFactory" factory-method="defaultInstance"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="instanceFactory" class="org.springframework.beans.factory.xml.InstanceFactory" scope="singleton">
|
||||
<property name="factoryBeanProperty"><value>instanceFactory</value></property>
|
||||
</bean>
|
||||
|
||||
<bean name="javaMailSession" class="org.springframework.beans.factory.xml.MailSession"
|
||||
factory-method="getDefaultInstance">
|
||||
<constructor-arg>
|
||||
<props>
|
||||
<prop key="mail.smtp.auth">true</prop>
|
||||
<prop key="mail.smtp.host"></prop>
|
||||
<prop key="mail.smtp.port"></prop>
|
||||
<prop key="mail.smtp.user">someuser</prop>
|
||||
<prop key="mail.smtp.password">somepw</prop>
|
||||
</props>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user