在编写测试用例的时候,最烦恼的就是在测试用例中注入一个bean了。SpringMVC 使用 ApplicationContext 实现 Bean 的加载
@Test
public void testContentList() {// 创建一个spring容器ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");// 从spring容中获取mapper的代理对象ContentService contentService = applicationContext.getBean(ContentService.class);EUDataGridResult result = contentService.getContentList(Long.valueOf(89), 0, 10);
}