我正在使用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.DependencyInjectionTestExecutionListener.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)
使用 SpringJunit4ClassRunner
和 ContextConfiguration
来加载上下文文件。
看看这篇文章。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:myContext.xml"})