简体   繁体   English

在NetBeans IDE中运行春季测试

[英]run spring test in netbeans ide

In IDE Netbeans I've created a test class with annotations 在IDE Netbeans中,我创建了带有注释的测试类

@ContextConfiguration(locations = {"classpath:spring/spring-test.xml"})
@RunWith(SpringJUnit4ClassRunner.class).

In Test Packages folder I've create folder spring/spring-test.xml with configuration. 在“测试包”文件夹中,我使用配置创建了文件夹spring / spring-test.xml。 But when I've try to run this test file I've got java.lang.IllegalStateException: Failed to load ApplicationContext. 但是,当我尝试运行此测试文件时,出现了java.lang.IllegalStateException:无法加载ApplicationContext。 What am I doing wrong and how to fix it? 我在做什么错以及如何解决?

Thanks 谢谢

PS Stack trace: PS堆栈跟踪:

ERROR TestContextManager [TestContextManager.java:234] Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@1d20e46] to prepare test instance [ru.javawebinar.topjava.service.UserServiceTest@1df84b8]
java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring/spring-test.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring/spring-test.xml] cannot be opened because it does not exist
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:343)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:251)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadBeanDefinitions(AbstractGenericContextLoader.java:257)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:124)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:108)
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:251)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
    ... 31 common frames omitted
Caused by: java.io.FileNotFoundException: class path resource [spring/spring-test.xml] cannot be opened because it does not exist
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
    ... 43 common frames omitted
INFO  XmlBeanDefinitionReader [XmlBeanDefinitionReader.java:316] Loading XML bean definitions from class path resource [spring/spring-test.xml]
ERROR TestContextManager [TestContextManager.java:234] Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@1d20e46] to prepare test instance [ru.javawebinar.topjava.service.UserServiceTest@bbffcd]
java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring/spring-test.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring/spring-test.xml] cannot be opened because it does not exist
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:343)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
Caused by: java.io.FileNotFoundException: class path resource [spring/spring-test.xml] cannot be opened because it does not exist
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
    ... 43 common frames omitted

INFO  XmlBeanDefinitionReader [XmlBeanDefinitionReader.java:316] Loading XML bean definitions from class path resource [spring/spring-test.xml]
ERROR TestContextManager [TestContextManager.java:234] Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@1d20e46] to prepare test instance [ru.javawebinar.topjava.service.UserServiceTest@eaa59a]
java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)

It should be useful to see the whole stack trace. 查看整个堆栈跟踪应该很有用。 However, I would check the test is finding the context xml configuration. 但是,我将检查测试是否找到上下文xml配置。 The XML should be placed in src/test/resources. XML应该放在src / test / resources中。 Another thing I would check is that all beans are find in this xml. 我要检查的另一件事是在此xml中找到了所有bean。 Check any dependency failing to initialise. 检查任何未初始化的依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从IDE运行Spring的集成测试 - Run integration-test for Spring from IDE 春季-从IDE运行测试-如何从文件'application-test.properties'加载测试属性 - Spring - Run test from IDE - how to load test properties from a file like 'application-test.properties' 带有Spring 4,NetBeans IDE的Hello World程序 - Hello World program with spring 4, netbeans IDE 如何解决 SPRING 中 FileNotFoundException 引起的 BeanDefinitionStoreException?(Netbeans IDE) - How to solve BeanDefinitionStoreException caused by FileNotFoundException in SPRING?(Netbeans IDE) 如何在NetBeans IDE中更新Spring和Hibernate库? - How can I update Spring and Hibernate libraries in NetBeans IDE? 无法使用NetBeans IDE 8.1,Glassfish 4.1运行简单的“ Hello World!”项目 - Unable to run a simple “Hello World!” project using NetBeans IDE 8.1, Glassfish 4.1 Gradle + Spring 项目将 jlink,但不会在 IDE 中使用 gradle 运行 - Gradle + Spring project will jlink, but not run using gradle inside IDE 使用 IDE 运行 Spring-boot 的 main - Run Spring-boot's main using IDE Maven / Spring:生成的WAR的自动测试运行 - Maven/Spring: Automatic Test Run of Generated WAR 如何使用@SpringBootTest 在 Spring 中运行集成测试 - How to run a integration test in Spring with @SpringBootTest
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM