Closed
Description
Thomas Zimmermann opened SPR-11571 and commented
It would be a convenient feature if the LazyConnectionDataSourceProxy would provide a public close() method that delegates to a (possibly configurable) destroy-method on the wrapped DataSource if one is present. This would avoid having to declare two datasource beans: one for the LazyConnectionDataSourceProxy and one for the underlying DataSource itself, so that the proper destroy-method can be called on it.
I'm initializing my DataSource as follows:
@Bean
public DataSource dataSource() {
PGSimpleDataSource dataSource = new PGSimpleDataSource();
// set properties ...
// set up connection pool, HikariCP in my case
HikariDataSource connectionPool = new HikariDataSource(config);
LazyConnectionDataSourceProxy lazyDataSource = new LazyConnectionDataSourceProxy();
lazyDataSource.setTargetDataSource(connectionPool);
// set properties ...
return lazyDataSource;
}
A suggestion how this could work would be:
@Bean(destroyMethod="close") // as per default
public DataSource dataSource() {
PGSimpleDataSource dataSource = new PGSimpleDataSource();
// set properties ...
// set up connection pool, HikariCP in my case
HikariDataSource connectionPool = new HikariDataSource(config);
LazyConnectionDataSourceProxy lazyDataSource = new LazyConnectionDataSourceProxy();
lazyDataSource.setTargetDataSource(connectionPool);
// set properties ...
lazyDataSource.setDestroyMethod("shutdown"); // or call "close" by default
return lazyDataSource;
}
Affects: 4.0.2
Issue Links:
- Notification for db connection acquired when LazyConnectionDataSourceProxy is used [SPR-17278] #21811 Notification for db connection acquired when LazyConnectionDataSourceProxy is used