Ensure that @LiquibaseDataSource is preferred to “normal” DataSource

Closes gh-6604
pull/6623/merge
Andy Wilkinson 8 years ago
parent 8424965a10
commit 7c54c3ff21

@ -116,12 +116,12 @@ public class LiquibaseAutoConfiguration {
}
private DataSource getDataSource() {
if (this.properties.getUrl() == null) {
return this.dataSource;
}
else if (this.liquibaseDataSource != null) {
if (this.liquibaseDataSource != null) {
return this.liquibaseDataSource;
}
else if (this.properties.getUrl() == null) {
return this.dataSource;
}
return DataSourceBuilder.create().url(this.properties.getUrl())
.username(this.properties.getUser())
.password(this.properties.getPassword()).build();

@ -25,8 +25,8 @@ import java.lang.annotation.Target;
import org.springframework.beans.factory.annotation.Qualifier;
/**
* Qualifier annotation for a DataSource to be injected in to Liquibase. If used for a second
* data source, the other (main) one would normally be marked as {@code @Primary}.
* Qualifier annotation for a DataSource to be injected in to Liquibase. If used for a
* second data source, the other (main) one would normally be marked as {@code @Primary}.
*
* @author Eddú Meléndez
* @since 1.4.1

@ -38,6 +38,7 @@ import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.FileCopyUtils;
@ -254,12 +255,20 @@ public class LiquibaseAutoConfigurationTests {
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
SpringLiquibase liquibase = this.context.getBean(SpringLiquibase.class);
assertThat(liquibase.getDataSource()).isNotNull();
assertThat(liquibase.getDataSource())
.isEqualTo(this.context.getBean("liquibaseDataSource"));
}
@Configuration
static class LiquibaseDataSourceConfiguration {
@Bean
@Primary
public DataSource normalDataSource() {
return DataSourceBuilder.create().url("jdbc:hsqldb:mem:normal").username("sa")
.build();
}
@LiquibaseDataSource
@Bean
public DataSource liquibaseDataSource() {

Loading…
Cancel
Save