Skip to content

Support bean disposal on ApplicationContext shutdown for Closeable beans [SPR-10034] #14668

@spring-projects-issues

Description

@spring-projects-issues

Stuart Gunter opened SPR-10034 and commented

When shutting down the ApplicationContext, beans that implement DisposableBean are automatically destroyed. However, not all libraries depend on Spring and instead rely on java.io.Closeable for proper cleanup.

It would be very useful if Spring also called the Closeable.close() method on any bean that implements it.

Is this viable, or would it conflict with other behaviour within the framework?

An example that highlighted this problem is the CouchbaseClient, which is constructed via a FactoryBean, which means the destroy-method cannot be specified on the bean created by the factory. This prevents the app context from shutting down correctly. With the above behaviour, CouchbaseClient could be modified to implement java.io.Closeable and be appropriately destroyed on application termination.


Affects: 3.2 RC1

Issue Links:

Referenced from: commits 9c6aa3e

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions