在編寫測試用例的時候,最煩惱的就是在測試用例中注入一個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);
}