3.1. Introduction to the Spring IoC container and beans .............................................27
3.2. Container overview ..........................................................................................27
Configuration metadata ...................................................................................28
Instantiating a container ..................................................................................30
Composing XML-based configuration metadata .......................................31
Using the container .........................................................................................32
3.3. Bean overview .................................................................................................32
Naming beans .................................................................................................34
Aliasing a bean outside the bean definition ...............................................34
Instantiating beans ..........................................................................................35
Instantiation with a constructor ................................................................36
Instantiation with a static factory method .................................................36
Instantiation using an instance factory method ..........................................37
3.4. Dependencies ...................................................................................................37
Dependency injection ......................................................................................37
Constructor-based dependency injection ...................................................38
Setter-based dependency injection ...........................................................40
Dependency resolution process ................................................................41
Examples of dependency injection ...........................................................42
Dependencies and configuration in detail .........................................................44
Straight values (primitives, Strings, and so on) .........................................44
References to other beans (collaborators) .................................................46
Inner beans .............................................................................................47
Collections .............................................................................................47
Null and empty string values ...................................................................50
XML shortcut with the p-namespace ........................................................50
Compound property names ......................................................................51
Using depends-on ...........................................................................................51
Lazy-initialized beans .....................................................................................52
Autowiring collaborators .................................................................................53
Limitations and disadvantages of autowiring ............................................54
Excluding a bean from autowiring ...........................................................55
Checking for dependencies ..............................................................................55
Method injection ............................................................................................56
Lookup method injection .........................................................................57
Arbitrary method replacement .................................................................58
3.5. Bean scopes .....................................................................................................60
The singleton scope ........................................................................................61
The prototype scope ........................................................................................62
Singleton beans with prototype-bean dependencies ...........................................63
Request, session, and global session scopes ......................................................63
Initial web configuration .........................................................................63
Request scope .........................................................................................64
Session scope .........................................................................................64
Global session scope ...............................................................................65
Spring Framework
3.0 Reference Documentation iii