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:
parent
bee7d24c1a
commit
91a40dd66c
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue