-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Closed
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancementA general enhancement
Milestone
Description
Chris Beams opened SPR-8751 and commented
Use case: creating a Hibernate SessionFactory
using the native Hibernate API or Spring 3.1's LocalSessionFactoryBuilder
:
@Bean
public SessionFactory sessionFactory() {
// ...
return sessionFactory;
}
In order to properly destroy the SessionFactory
on Spring container shutdown, the user must specify @Bean(destroyMethod="close")
:
@Bean(destroyMethod="close")
public SessionFactory sessionFactory() {
// ...
return sessionFactory;
}
This is easy to forget and should be specified every time anyway. "destroy method inference" will detect well-known destroy methods (e.g. public no-arg close()
methods) and automatically register them as the destroy-method against the underlying bean definition.
Users may disable destroy method inference by explicitly specifying empty string (""
) for the value of destroyMethod
:
@Bean(destroyMethod="") // call no destroy method and do not attempt to infer one
public SessionFactory sessionFactory() {
// ...
return sessionFactory;
}
Issue Links:
- Document how to prevent a JNDI DataSource retrieved using JavaConfig to be removed on shutdown of the context [SPR-12551] #17153 Document how to prevent a JNDI DataSource retrieved using JavaConfig to be removed on shutdown of the context
- Add note to reference material about difference between XML destroy-method and @Bean destroyMethod behavior [SPR-12534] #17139 Add note to reference material about difference between XML destroy-method and
@Bean
destroyMethod behavior - Support bean disposal on ApplicationContext shutdown for Closeable beans [SPR-10034] #14668 Support bean disposal on ApplicationContext shutdown for Closeable beans
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancementA general enhancement