Reputation: 649
I would like to load liquibase properties and initiate H2 database when I set use.liquibase is true. In all the other cases, I would like to go to the corresponding RDBMS instance. I have code something like this
@PropertySource("liquibase.properties")
@ConditionalOnProperty(value = "use.liquibase", havingValue = "true")
@Configuration
public class LiquibaseDaoConfig {
@Bean(name = "dataSource")
public DataSource dataSource(...) {
//load properties from liquibase.properties
//return H2 Datasource
}
}
@Configuration
public class DaoConfig{
@Bean(name = "dataSource")
@ConditionalOnProperty(value = "use.liquibase", havingValue = "false")
@Primary
public DataSource dataSource(....) {
// return Oracle Datatsource
}
@Bean
public StuffDao stuffDao(DataSource dataSource) {
return new StuffDaoImpl(dataSource);
}
}
use.liquibase = true
I get No qualifying bean of type 'javax.sql.DataSource' available error. What am I doing wrong? Please help.
Upvotes: 0
Views: 705
Reputation: 32517
havingValue = "false"
this will work if and only if property value will be exactly false. It wont work for for any other value that would normally resolve to logical false like eg. missing value.
So in general, check for typos and if given configuration classes arr on componen scan path
Upvotes: 1