Disable unnecessary database initialization

If a DataSource class is found in the classpath then
EmbeddedDataSourceConfiguration will not be used, so the in-memory
database will not be shutdown on application context closing.
As a result, unnecessary database initialization may cause subsequent
tests to fail, for example see [1].

[1] https://github.com/spring-projects/spring-boot/issues/1712
This commit is contained in:
Alexander Tokarev 2015-10-01 16:11:29 +03:00 committed by Andy Wilkinson
parent bee7d24c1a
commit 91a40dd66c
2 changed files with 5 additions and 0 deletions

View File

@ -298,6 +298,8 @@ public class SecurityAutoConfigurationTests {
this.context.setServletContext(new MockServletContext());
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.url:jdbc:hsqldb:mem:testsecdb");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.initialize:false");
this.context.register(EntityConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,

View File

@ -22,6 +22,7 @@ import org.junit.After;
import org.junit.Test;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -85,6 +86,8 @@ public class TransactionAutoConfigurationTests {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
applicationContext.register(configs);
applicationContext.register(TransactionAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(applicationContext,
"spring.datasource.initialize:false");
applicationContext.refresh();
this.context = applicationContext;
}