Dao层注入失败,查看后,发现注解都写的无误,经朋友的指点,在测试类上加了一句“@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={“classpath:spring/applicationContext-tx.xml”,“classpath:spring/applicationContext-service.xml”,“classpath:spring/applicationContext-dao.xml”})”
经测试,Dao可以注入,不再为null
@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);
}
}