Skip to content

Support automatic detection of close methods [SPR-8114] #12768

Closed
@spring-projects-issues

Description

@spring-projects-issues

Chris Beams opened SPR-8114 and commented

When using Spring's FactoryBean types such as LocalSessionFactoryBean destruction of the actual bean (the Hibernate Session in the case of LSFB) is usually handled automatically by the FactoryBean.

However, when using Spring's new *Builder APIs within @Bean methods, no FactoryBean-like object is registered with the container. This means that it is up to the user to remember to configure the destroy-method attribute of the @Bean annotation, which is likely to be forgotten.

To remedy this situation, Spring should automatically detect common close/destruction method names and signatures and automatically invoke them at container shutdown time.

Obviously, Spring's DisposableBean is already supported in this way, as are methods annotated with @PreDestroy. When dealing with third-party types, however, the user is not at liberty to add these interfaces/annotations. In the case of Hibernate's Session interface, the method to be called is

public Connection close() throws HibernateException;

As this method is not annotated in any way nor does it implement any standard interface with destruction semantics, we can only assume based on it's name that it is to be invoked.


Attachments:

Issue Links:

Referenced from: commits 5c27a04, 1a8531b

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions