Spring Framework Reference Documentation
4.2.1.RELEASE Spring Framework iv
III. Core Technologies .............................................................................................................. 31
6. The IoC container ........................................................................................................ 32
6.1. Introduction to the Spring IoC container and beans .............................................. 32
6.2. Container overview ............................................................................................ 32
Configuration metadata ..................................................................................... 33
Instantiating a container .................................................................................... 34
Composing XML-based configuration metadata .......................................... 35
Using the container .......................................................................................... 36
6.3. Bean overview ................................................................................................... 36
Naming beans .................................................................................................. 37
Aliasing a bean outside the bean definition ................................................ 38
Instantiating beans ........................................................................................... 39
Instantiation with a constructor .................................................................. 39
Instantiation with a static factory method .................................................... 40
Instantiation using an instance factory method ........................................... 40
6.4. Dependencies ................................................................................................... 41
Dependency Injection ....................................................................................... 41
Constructor-based dependency injection .................................................... 42
Setter-based dependency injection ............................................................ 44
Dependency resolution process ................................................................. 45
Examples of dependency injection ............................................................. 46
Dependencies and configuration in detail ........................................................... 48
Straight values (primitives, Strings, and so on) ........................................... 48
References to other beans (collaborators) .................................................. 49
Inner beans .............................................................................................. 50
Collections ............................................................................................... 50
Null and empty string values ..................................................................... 53
XML shortcut with the p-namespace .......................................................... 53
XML shortcut with the c-namespace .......................................................... 54
Compound property names ....................................................................... 55
Using depends-on ............................................................................................ 56
Lazy-initialized beans ....................................................................................... 56
Autowiring collaborators .................................................................................... 57
Limitations and disadvantages of autowiring ............................................... 58
Excluding a bean from autowiring .............................................................. 58
Method injection ............................................................................................... 59
Lookup method injection ........................................................................... 60
Arbitrary method replacement ................................................................... 61
6.5. Bean scopes ..................................................................................................... 62
The singleton scope ......................................................................................... 63
The prototype scope ......................................................................................... 64
Singleton beans with prototype-bean dependencies ............................................ 65
Request, session, and global session scopes .................................................... 65
Initial web configuration ............................................................................ 66
Request scope ......................................................................................... 66
Session scope .......................................................................................... 67
Global session scope ............................................................................... 67
Application scope ..................................................................................... 67
Scoped beans as dependencies ................................................................ 67
Custom scopes ................................................................................................ 69