我按照http://spring.io/guides/tutorials/rest/下的教程松散,似乎无法对我的MVCConfig传递进行集成测试。
它抛出以下异常:
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)
此处的完整堆栈跟踪:http://pastebin.com/B3tWS3hH
我尝试在完成的教程中运行测试,但也失败了。
整合测试:
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = MVCConfig.class)
public class RestDomainIntegrationTest {
@Autowired
WebApplicationContext wac;
MockMvc mockMvc;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}
@Test
public void thatRestDomainCanBeAccessed() throws Exception {
mockMvc.perform(get("/")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk());
}
}
MVCConfig
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.scrumster.rest.controller"})
public class MVCConfig { }
我错过了什么吗?我搜索了一些相关问题,但似乎无法找到适合该法案的任何内容。