Spring Framework
3.2.2.RELEASE
Spring Framework
Reference Documentation iv
Instantiation using an instance factory method ........................................... 42
5.4. Dependencies ................................................................................................... 44
Dependency injection ....................................................................................... 44
Constructor-based dependency injection .................................................... 44
Setter-based dependency injection ............................................................ 46
Dependency resolution process ................................................................. 47
Examples of dependency injection ............................................................. 48
Dependencies and configuration in detail ........................................................... 50
Straight values (primitives, Strings, and so on) ....................................... 50
References to other beans (collaborators) .................................................. 52
Inner beans .............................................................................................. 53
Collections ............................................................................................... 53
Null and empty string values ..................................................................... 56
XML shortcut with the p-namespace .......................................................... 56
XML shortcut with the c-namespace .......................................................... 58
Compound property names ....................................................................... 58
Using depends-on .......................................................................................... 59
Lazy-initialized beans ....................................................................................... 59
Autowiring collaborators .................................................................................... 60
Limitations and disadvantages of autowiring ............................................... 61
Excluding a bean from autowiring .............................................................. 61
Method injection ............................................................................................... 62
Lookup method injection ........................................................................... 63
Arbitrary method replacement ................................................................... 64
5.5. Bean scopes ..................................................................................................... 65
The singleton scope ......................................................................................... 66
The prototype scope ......................................................................................... 67
Singleton beans with prototype-bean dependencies ............................................ 68
Request, session, and global session scopes .................................................... 68
Initial web configuration ............................................................................ 69
Request scope ......................................................................................... 69
Session scope .......................................................................................... 70
Global session scope ............................................................................... 70
Scoped beans as dependencies ................................................................ 70
Custom scopes ................................................................................................ 72
Creating a custom scope .......................................................................... 72
Using a custom scope .............................................................................. 73
5.6. Customizing the nature of a bean ....................................................................... 74
Lifecycle callbacks ............................................................................................ 74
Initialization callbacks ............................................................................... 75
Destruction callbacks ................................................................................ 75
Default initialization and destroy methods .................................................. 76
Combining lifecycle mechanisms ............................................................... 77
Startup and shutdown callbacks ................................................................ 78
Shutting down the Spring IoC container gracefully in non-web applications
................................................................................................................. 80
ApplicationContextAware and BeanNameAware ........................................ 80
Other Aware interfaces .................................................................................... 81
5.7. Bean definition inheritance ................................................................................. 82
5.8. Container Extension Points ................................................................................ 84