Spring Framework Reference Documentation
4.3.8.RELEASE Spring Framework v
7.5. Bean scopes ..................................................................................................... 70
The singleton scope ......................................................................................... 71
The prototype scope ......................................................................................... 72
Singleton beans with prototype-bean dependencies ............................................ 73
Request, session, global session, application, and WebSocket scopes ................. 73
Initial web configuration ............................................................................ 74
Request scope ......................................................................................... 74
Session scope .......................................................................................... 75
Global session scope ............................................................................... 75
Application scope ..................................................................................... 75
Scoped beans as dependencies ................................................................ 76
Custom scopes ................................................................................................ 78
Creating a custom scope .......................................................................... 78
Using a custom scope .............................................................................. 79
7.6. Customizing the nature of a bean ....................................................................... 80
Lifecycle callbacks ............................................................................................ 80
Initialization callbacks ............................................................................... 81
Destruction callbacks ................................................................................ 81
Default initialization and destroy methods .................................................. 82
Combining lifecycle mechanisms ............................................................... 83
Startup and shutdown callbacks ................................................................ 84
Shutting down the Spring IoC container gracefully in non-web applications
................................................................................................................. 86
ApplicationContextAware and BeanNameAware ................................................. 86
Other Aware interfaces ..................................................................................... 87
7.7. Bean definition inheritance ................................................................................. 88
7.8. Container Extension Points ................................................................................ 90
Customizing beans using a BeanPostProcessor ................................................. 90
Example: Hello World, BeanPostProcessor-style ........................................ 91
Example: The RequiredAnnotationBeanPostProcessor ............................... 93
Customizing configuration metadata with a BeanFactoryPostProcessor ................ 93
Example: the Class name substitution PropertyPlaceholderConfigurer .......... 94
Example: the PropertyOverrideConfigurer .................................................. 95
Customizing instantiation logic with a FactoryBean ............................................. 96
7.9. Annotation-based container configuration ............................................................ 96
@Required ....................................................................................................... 98
@Autowired ..................................................................................................... 98
Fine-tuning annotation-based autowiring with @Primary .................................... 101
Fine-tuning annotation-based autowiring with qualifiers ..................................... 102
Using generics as autowiring qualifiers ............................................................ 107
CustomAutowireConfigurer .............................................................................. 108
@Resource .................................................................................................... 108
@PostConstruct and @PreDestroy .................................................................. 110
7.10. Classpath scanning and managed components ................................................ 110
@Component and further stereotype annotations ............................................. 110
Meta-annotations ............................................................................................ 111
Automatically detecting classes and registering bean definitions ........................ 112
Using filters to customize scanning .................................................................. 113
Defining bean metadata within components ..................................................... 114
Naming autodetected components ................................................................... 117