gavlyukovskiy/spring-boot-data-source-decorator

How to decorate two datasources?

Closed this issue · 1 comments

Hello.
I have 2 datasources - for ex spring.a-datasource.... and spring.b-datasource....
And I want to use flexy-pool-spring-boot-starter.
How can I create 2 decorated datasources?
Thanx.

Hi @makaxel, there are couple of ways you can manage multiple datasources, so it's better to consult with the documentation. Usually you can define them in the configuration, like that:

        @Bean
        @Primary
        @ConfigurationProperties("spring.a-datasource")
        public DataSource dataSourceA() {
            return new HikariDataSource();
        }

        @Bean
        @ConfigurationProperties("spring.b-datasource")
        public DataSource dataSourceB() {
            return new HikariDataSource();
        }

in this case auto-configuration metadata will work correctly. But that's spring boot's part and is not related to my library's code.

Regarding decorating - all data sources (defined in a way above or in any other way) are decorated, in your case with flexy-pool data source.

Please let me know if you have any questions.