gavlyukovskiy/spring-boot-data-source-decorator

FlexyPoolDataSourceDecorator won't be created if datasource bean in context is interface DataSource

Opened this issue · 2 comments

given such example definition of data source in application code:

    @Bean
    @Primary
    @ConfigurationProperties(prefix = "database.application.datasource.hikari")
    DataSource applicationDataSource(@Qualifier("applicationDataSourceProperties") DataSourceProperties applicationDataSourceProperties) {
        return applicationDataSourceProperties
                .initializeDataSourceBuilder()
                .driverClassName(applicationDataSourceProperties.getDriverClassName())
                .type(HikariDataSource.class)
                .build();
    }

although its Hikari, but returned as interface DataSource, the FlexyPoolDataSourceDecorator bean won't be created, resulting in datasource not wrapped in Flexy goodies.

This is because one of conditionals on HikariFlexyConfiguration (configuration creating the decorator bean) is HikariDataSource

Since flexy pool has specific adapters for each pool, it is required to know the concrete type of datasource to create proper decorator. Are there any reasons you can not use HikariDataSource as the return type?

I did change it to return specific type in the end, but I had to dig on why doesn't it work out of the box. To improve easiness of use, I think its either worth mentioning it in docs somewhere or autoconfig should be constructed in slightly different way (eg. iterate over all datasources and check their types)