【Spring】SpringMVC 項目,編寫 test 測試用例

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章