entry The IoC container

4.3.9.RELEASE Spring Framework 60 child definition; specifying the merge attribute on a parent collection definition is redundant and will not result in the desired merging. Strongly-typed collection With the introduction of generic types in Java 5, you can use strongly typed collections. That is, it is possible to declare a Collection type such that it can only contain String elements for example. If you are using Spring to dependency-inject a strongly-typed Collection into a bean, you can take advantage of Spring’s type-conversion support such that the elements of your strongly-typed Collection instances are converted to the appropriate type prior to being added to the Collection . public class Foo { private MapString, Float accounts; public void setAccountsMapString, Float accounts { this .accounts = accounts; } } beans bean id = foo class = x.y.Foo property name = accounts map entry key = one value = 9.99 entry key = two value =

2.75 entry

key = six value = 3.99 map property bean beans When the accounts property of the foo bean is prepared for injection, the generics information about the element type of the strongly-typed MapString, Float is available by reflection. Thus Spring’s type conversion infrastructure recognizes the various value elements as being of type Float , and the string values 9.99, 2.75 , and 3.99 are converted into an actual Float type. Null and empty string values Spring treats empty arguments for properties and the like as empty Strings . The following XML-based configuration metadata snippet sets the email property to the empty String value . bean class = ExampleBean property name = email value = bean The preceding example is equivalent to the following Java code: exampleBean.setEmail The null element handles null values. For example: bean class = ExampleBean property name = email null property bean The above configuration is equivalent to the following Java code: exampleBean.setEmailnull 4.3.9.RELEASE Spring Framework 61 XML shortcut with the p-namespace The p-namespace enables you to use the bean element’s attributes, instead of nested property elements, to describe your property values andor collaborating beans. Spring supports extensible configuration formats with namespaces , which are based on an XML Schema definition. The beans configuration format discussed in this chapter is defined in an XML Schema document. However, the p-namespace is not defined in an XSD file and exists only in the core of Spring. The following example shows two XML snippets that resolve to the same result: The first uses standard XML format and the second uses the p-namespace. beans xmlns = http:www.springframework.orgschemabeans xmlns:xsi = http:www.w3.org2001XMLSchema-instance xmlns:p = http:www.springframework.orgschemap xsi:schemaLocation = http:www.springframework.orgschemabeans http:www.springframework.orgschemabeansspring-beans.xsd bean name = classic class = com.example.ExampleBean property name = email value = foobar.com bean bean name = p-namespace class = com.example.ExampleBean

p:email =