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);
}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM