SSM+mybatis单元测试

初学SSM+mybatis单元测试遇到的问题,dao注入后为null

Dao层注入失败,查看后,发现注解都写的无误,经朋友的指点,

在测试类上加了一句“@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration(locations={“classpath:spring/applicationContext-tx.xml”,“classpath:spring/applicationContext-service.xml”,“classpath:spring/applicationContext-dao.xml”})” 经测试,Dao可以注入,不再为null --------------------- 作者:旅途上的背包客 来源:CSDN 原文:https://blog.csdn.net/u012799877/article/details/83056657?utm_source=copy 版权声明:本文为博主原创文章,转载请附上博文链接!


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:spring/applicationContext-tx.xml","classpath:spring/applicationContext-service.xml","classpath:spring/applicationContext-dao.xml"})
public class TaskInfoTest {
@Autowired
TaskService taskService;
@Test
public void test(){
TaskInfo taskInfo = new TaskInfo();
taskInfo.setTid(2);
taskInfo.setTname("taskname");
taskInfo.setStatus("成功");
taskInfo.setBtime("2018-10-12");
taskInfo.setEtime("2018-10-15");
taskService.add(taskInfo);
}
}

猜你喜欢

转载自www.cnblogs.com/songhaozhi080616/p/9790045.html