spring整合mybatis时不要忘了导spring-test包
注意 1.类上面需要加两个注解
2:Caused by: java.lang.IllegalStateException: SpringJUnit4ClassRunner requires JUnit 4.12 or higher.
举个栗子
1 package com.qianfeng.test; 2 3 import com.qianfeng.restfull.beans.TbHotel; 4 import com.qianfeng.restfull.dao.IHotelDAO; 5 import org.junit.Test; 6 import org.junit.runner.RunWith; 7 import org.springframework.beans.factory.annotation.Autowired; 8 import org.springframework.test.context.ContextConfiguration; 9 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 11 import java.util.List; 12 13 @RunWith(SpringJUnit4ClassRunner.class) 14 @ContextConfiguration("classpath:spring.xml") 15 public class SpringTest { 16 17 @Autowired 18 private IHotelDAO hotelDAO; 19 20 @Test 21 public void testCase1(){ 22 try { 23 List<TbHotel> hotelList = hotelDAO.queryHotelByPage(0); 24 System.out.println(hotelList); 25 } catch (Exception e) { 26 e.printStackTrace(); 27 } 28 } 29 }
历经苦难而不厌,此乃阿修罗之道。
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步