运行 JUnit 测试用例时无法加载应用程序上下文错误



我正在使用JUnit进行Web服务(Springs)的单元测试。

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration({"classpath:WSexample/config/service/WSexample-service.xml‌"}) 

并且测试文件位于WSexample/test/find/controller位置

我正在使用上面的代码来加载一个 xml 文件。 它正在抛出"无法加载应用程序上下文"错误。

java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.TestContext.getApplicationContext(TestContext.j ava:308) at org.springframework.test.context.support.DependencyInjectionTestExecutionListene

r.injectDependencies(DependencyInjectionTestExecutionListener.java:109) at org.springframework.test.context.support.DependencyInjectionTestExecutionListene r.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestCont extManager.java:321)

您可能需要

使用 SpringJunit4ClassRunnerContextConfiguration 来加载上下文文件。

看看这篇文章。

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations={"classpath:myContext.xml"}) 

相关内容

最新更新