Spring Framework
4.0.0.RELEASE
Spring Framework
Reference Documentation iii
Instantiation using an instance factory method ........................................... 30
4.4. Dependencies ................................................................................................... 32
Dependency injection ....................................................................................... 32
Constructor-based dependency injection .................................................... 32
Setter-based dependency injection ............................................................ 34
Dependency resolution process ................................................................. 35
Examples of dependency injection ............................................................. 36
Dependencies and configuration in detail ........................................................... 38
Straight values (primitives, Strings, and so on) ........................................... 38
References to other beans (collaborators) .................................................. 40
Inner beans .............................................................................................. 41
Collections ............................................................................................... 41
Null and empty string values ..................................................................... 44
XML shortcut with the p-namespace .......................................................... 44
XML shortcut with the c-namespace .......................................................... 46
Compound property names ....................................................................... 46
Using depends-on ............................................................................................ 47
Lazy-initialized beans ....................................................................................... 47
Autowiring collaborators .................................................................................... 48
Limitations and disadvantages of autowiring ............................................... 49
Excluding a bean from autowiring .............................................................. 50
Method injection ............................................................................................... 50
Lookup method injection ........................................................................... 51
Arbitrary method replacement ................................................................... 53
4.5. Bean scopes ..................................................................................................... 54
The singleton scope ......................................................................................... 55
The prototype scope ......................................................................................... 55
Singleton beans with prototype-bean dependencies ............................................ 56
Request, session, and global session scopes .................................................... 56
Initial web configuration ............................................................................ 57
Request scope ......................................................................................... 58
Session scope .......................................................................................... 58
Global session scope ............................................................................... 58
Scoped beans as dependencies ................................................................ 58
Custom scopes ................................................................................................ 60
Creating a custom scope .......................................................................... 60
Using a custom scope .............................................................................. 61
4.6. Customizing the nature of a bean ....................................................................... 62
Lifecycle callbacks ............................................................................................ 62
Initialization callbacks ............................................................................... 63
Destruction callbacks ................................................................................ 64
Default initialization and destroy methods .................................................. 64
Combining lifecycle mechanisms ............................................................... 66
Startup and shutdown callbacks ................................................................ 66
Shutting down the Spring IoC container gracefully in non-web applications
................................................................................................................. 68
ApplicationContextAware and BeanNameAware ................................................. 68
Other Aware interfaces ..................................................................................... 69
4.7. Bean definition inheritance ................................................................................. 71
4.8. Container Extension Points ................................................................................ 72
- 1
- 2
前往页