Description
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:
- mylyn-context.zip (4.40 kB)
- mylyn-context.zip (4.40 kB)
Issue Links:
- Provide alternatives to using FactoryBean types within @Bean methods [SPR-7418] #12076 Provide alternatives to using FactoryBean types within
@Bean
methods