25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5 ■ Working with Collections and Custom Types<br />

Listing 5-6 Merge Example<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

In Listing 5-6, you can get anotherTypeDAO and it will contain the six types. But how does the <strong>Spring</strong> <strong>Framework</strong><br />

know about the merging? This is because your typeDAO bean has defined the attribute abstract with a value of true.<br />

This means that it cannot be instantiated; it will be seen as a template by the container. All of the children beans<br />

that make a reference of this parent bean will inherit all of the properties, such as the case of anotherTypeDAO that<br />

inherited all the types properties, in this case the join/merge of the map. Also, you need to see that anotherTypeDAO<br />

uses the attribute parent, making the reference to the parent bean the typeDAO.<br />

If you think that <strong>Spring</strong> has another way to express collections in the XML based configuration, you are right. The<br />

<strong>Spring</strong> <strong>Framework</strong> also supports, based on a namespace, a “shortcut” for declaring collections. Now you have more<br />

options for using collections. See Listing 5-7 for an XML configuration example.<br />

Listing 5-7. mydocuments-util-context.xml<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

58

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!