Skip to content

@FlywayDataSource does not work in an application that has multiple datasources #20598

Closed
@ta7uw

Description

@ta7uw

I upgraded spring-boot version from 2.1.2 to 2.2.2 in my project.
After upgrading, FlywayAutoConfiguration has been failed by NoUniqueBeanDefinitionException.

My application has multiple datasources and uses flyway whch uses the datasource is annotated with@FlywayDataSource.
They are defined such as the following configuration class.

@Configuration
public class DataSourceConfig {
    @Bean
    @ConfigurationProperties(prefix = "datasource.main")
    public DataSource mainDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean
    @ConfigurationProperties(prefix = "datasource.secondary")
    public DataSource secondaryDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean
    @FlywayDataSource
    public DataSource flywayDataSource(DataSource mainDataSource) {
        return mainDataSource;
    }
}

This problem may have been caused by the change of this commit (de0c065).

In version 2.1.2, getIfUnique() was called in FlywayAutoConfiguration.class to get a unique datasource.

But, in version 2.2.2 getIfAvailable() is called in FlywayAutoConfiguration.class to get a unique datasource.

Is this change the migration mistake ?
as it is now, @FlywayDataSource does not work well for multiple datasources.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: supersededAn issue that has been superseded by anothertype: regressionA regression from a previous release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions