Spring boot 运行springboot测试时出错,原因是org.springframework.boot.context.properties.bind.BindException

Spring boot 运行springboot测试时出错,原因是org.springframework.boot.context.properties.bind.BindException,spring-boot,java-8,java-stream,junit4,spring-boot-test,Spring Boot,Java 8,Java Stream,Junit4,Spring Boot Test,我有两个junit测试,它们扩展了一个抽象类 @Configuration @Profile("test") public class TestConfig extends SpringBootServletInitializer { //Config implementations } 当我运行测试类TestB和TestC时,出现以下错误 java.lang.IllegalStateException:未能加载ApplicationContext 位于org.spring

我有两个junit测试,它们扩展了一个抽象类

@Configuration
@Profile("test")
public class TestConfig extends SpringBootServletInitializer {
//Config implementations
}
当我运行测试类TestB和TestC时,出现以下错误

java.lang.IllegalStateException:未能加载ApplicationContext 位于org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) 位于org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) 位于org.springframework.test.context.web.ServletTestExecutionListener.SetupRequestContextIfNeeded(ServletTestExecutionListener.java:190) 位于org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132) 位于org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246) 位于org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227) 位于org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectCall(SpringJUnit4ClassRunner.java:289) 位于org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 位于org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291) 位于org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246) 位于org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) 位于org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 位于org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 位于org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 访问org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 位于org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 位于org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) 位于org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) 位于org.junit.runners.ParentRunner.run(ParentRunner.java:363) 位于org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) 位于org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264) 位于org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153) 位于org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124) 位于org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200) 位于org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153) 位于org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103) 原因:java.lang.IllegalStateException:未能从位置“classpath:/application.properties”加载属性源 位于org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:526) 位于org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadForFileExtension(ConfigFileApplicationListener.java:475) 位于org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:445) 位于org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$null$6(ConfigFileApplicationListener.java:427) 位于java.lang.Iterable.forEach(Iterable.java:75) 位于org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$load$7(ConfigFileApplicationListener.java:427) 位于java.lang.Iterable.forEach(Iterable.java:75) 位于org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:424) 位于org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:323) 位于org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:204) 位于org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:188) 位于org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:178) 位于org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:166) 位于org.springframework.context.event.SimpleApplicationEventMulticast.doInvokeListener(SimpleApplicationEventMulticast.java:172) 位于org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) 位于org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) 位于org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) 位于org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:76) 位于org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53) 位于org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:342) 位于org.springframework.boot.SpringApplication.run(SpringApplication.java:305) 位于org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:121) 位于org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) 位于org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) 位于org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestCon
public class abstract TestA {
// common implementation
}
@RunWith(SpringRunner.class)
@SpringBootTest(TestConfig.class)
@WebAppConfiguration
@DirtiesContext
@ActiveProfile("test")
public class TestB extends TestA {
// Tests
}
@RunWith(SpringRunner.class)
@SpringBootTest(TestConfig.class)
@WebAppConfiguration
@DirtiesContext
@ActiveProfile("test")
public class TestC extends TestA {
}