Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在IntelliJ Community 2017.1中运行Spring启动测试时出错_Java_Spring_Spring Mvc_Intellij Idea_Junit - Fatal编程技术网

Java 在IntelliJ Community 2017.1中运行Spring启动测试时出错

Java 在IntelliJ Community 2017.1中运行Spring启动测试时出错,java,spring,spring-mvc,intellij-idea,junit,Java,Spring,Spring Mvc,Intellij Idea,Junit,这是一种非常奇怪的行为。我有一个Spring boot应用程序,运行良好。几天以来(我只是将应用程序切换到另一个Git repo,如果它有什么意义的话),每次我用IntelliJ运行测试时,我都会发现错误: java.lang.IllegalStateException:无法在处加载ApplicationContext org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext

这是一种非常奇怪的行为。我有一个Spring boot应用程序,运行良好。几天以来(我只是将应用程序切换到另一个Git repo,如果它有什么意义的话),每次我用IntelliJ运行测试时,我都会发现错误:

java.lang.IllegalStateException:无法在处加载ApplicationContext org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) 在 org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) 在 org.springframework.test.context.web.ServletTestExecutionListener.SetupRequestContextIfEssential(ServletTestExecutionListener.java:189) 在 org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:131) 在 org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230) 在 org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)位于 org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectCall(SpringJUnit4ClassRunner.java:287) 在 org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 在 org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289) 在 org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247) 在 org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94) 位于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:191) 位于org.junit.runner.JUnitCore.run(JUnitCore.java:137) JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) 在 intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) 在 com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) 在 com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) 原因:java.lang.IllegalStateException:未能添加 PropertySource to Environment at org.springframework.test.context.support.TestPropertySourceUtils.addPropertiesFilesToEnvironment(TestPropertySourceUtils.java:198) 在 SpringBootContextLoader.loadContext(SpringBootContextLoader.java:100) 在 org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) 在 org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) ... 由于以下原因,省略了24个公共框架: java.io.FileNotFoundException:类路径资源 无法打开[com/mycompany/myproject/test.properties],因为它 不存在于 org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172) 在 org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:154) 在 org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:98) 在 org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:72) 在 org.springframework.core.io.support.PropertiesLoaderUtils.loadProperties(PropertiesLoaderUtils.java:58) 在 org.springframework.core.io.support.ResourcePropertySource.(ResourcePropertySource.java:84) 在 org.springframework.test.context.support.TestPropertySourceUtils.addPropertiesFilesToEnvironment(TestPropertySourceUtils.java:194) ... 27公共帧省略09:54:42.723[主]调试 org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener -测试类之后:上下文[DefaultTestContext@371a67ectestClass=AudioVideoControllerTest,testInstance=[null],testMethod=[null], testException=[null],mergedContextConfiguration= [WebMergedContextConfiguration@5ed828d测试类= AudioVideoControllerTest,位置='{}',类='{class com.mycompany.myproject.myprojectApplication}, ContextInitializerClass='[]',activeProfiles='{}', 物业资源配置= “{classpath:/com/mycompany/myproject/test.properties}”, 财产来源财产= “{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}”, 上下文定制器= 设置[org.springframework.boot.test.context]。SpringBootTestContextCustomizer@548e7350, org.springframework.boot.test.context.filter。ExcludeFilterContextCustomizer@77cd7a0, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@754ba872, org.springframework.boot.test.mock.mockito。MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.properties。PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@13805618], resourceBasePath='src/main/webapp',contextLoader= 'org.s
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = MyApplication.class)
@TestPropertySource(locations="test.properties")
@SpringBootTest
public class AudioVideoControllerTest {...}