diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java index 152b87b31d..7c3f3e007a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java @@ -21,7 +21,6 @@ import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; import liquibase.integration.spring.SpringLiquibase; -import liquibase.servicelocator.ServiceLocator; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -35,7 +34,6 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.liquibase.CommonsLoggingLiquibaseLogger; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -52,6 +50,7 @@ import org.springframework.util.Assert; * @author Dave Syer * @author Phillip Webb * @author Eddú Meléndez + * @author Andy Wilkinson * @since 1.1.0 */ @Configuration @@ -95,9 +94,6 @@ public class LiquibaseAutoConfiguration { + " (please add changelog or check your Liquibase " + "configuration)"); } - ServiceLocator serviceLocator = ServiceLocator.getInstance(); - serviceLocator.addPackageToScan( - CommonsLoggingLiquibaseLogger.class.getPackage().getName()); } @Bean diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java index 1ea2f94d95..83d3a3c57a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java @@ -34,6 +34,8 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.liquibase.CommonsLoggingLiquibaseLogger; +import org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener; +import org.springframework.boot.test.rule.OutputCapture; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -48,8 +50,8 @@ import static org.assertj.core.api.Assertions.assertThat; * Tests for {@link LiquibaseAutoConfiguration}. * * @author Marcel Overdijk - * @author Andy Wilkinson * @author Eddú Meléndez + * @author Andy Wilkinson */ public class LiquibaseAutoConfigurationTests { @@ -59,12 +61,16 @@ public class LiquibaseAutoConfigurationTests { @Rule public TemporaryFolder temp = new TemporaryFolder(); + @Rule + public OutputCapture outputCapture = new OutputCapture(); + private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); @Before public void init() { EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.name:liquibasetest"); + new LiquibaseServiceLocatorApplicationListener().onApplicationEvent(null); } @After @@ -203,6 +209,7 @@ public class LiquibaseAutoConfigurationTests { SpringLiquibase liquibase = this.context.getBean(SpringLiquibase.class); Object log = ReflectionTestUtils.getField(liquibase, "log"); assertThat(log).isInstanceOf(CommonsLoggingLiquibaseLogger.class); + assertThat(this.outputCapture.toString()).doesNotContain(": liquibase:"); } @Test diff --git a/spring-boot/src/main/java/org/springframework/boot/liquibase/LiquibaseServiceLocatorApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/liquibase/LiquibaseServiceLocatorApplicationListener.java index a5d2502b31..6a32be7677 100644 --- a/spring-boot/src/main/java/org/springframework/boot/liquibase/LiquibaseServiceLocatorApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/liquibase/LiquibaseServiceLocatorApplicationListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,8 +51,12 @@ public class LiquibaseServiceLocatorApplicationListener private static class LiquibasePresent { public void replaceServiceLocator() { - ServiceLocator.setInstance(new CustomResolverServiceLocator( - new SpringPackageScanClassResolver(logger))); + CustomResolverServiceLocator customResolverServiceLocator = new CustomResolverServiceLocator( + new SpringPackageScanClassResolver(logger)); + customResolverServiceLocator.addPackageToScan( + CommonsLoggingLiquibaseLogger.class.getPackage().getName()); + ServiceLocator.setInstance(customResolverServiceLocator); + liquibase.logging.LogFactory.reset(); } }