Skip to content

Add close() method to LazyConnectionDataSourceProxy [SPR-11571] #16195

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 3c58be0, 6551aa6

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: bulk-closedAn outdated, unresolved issue that's closed in bulk as part of a cleaning process

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions