使用junit测试ssh框架一般流程

来源:互联网 发布:通用网络视频监控软件 编辑:程序博客网 时间:2024/06/01 09:47

1.使用代码加载applicationContext

public class CustomerDaoImplTest {

    @Test
    public void test() {
        ApplicationContext a = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        CustomerDao customerDao = (CustomerDao) a.getBean("CustomerDao");
        Customer customer = customerDao.findById(23l);
        System.out.println(customer.getCustName());
    }

}

2.使用注解加载applicationContext

@ContextConfiguration(location={"classpath:applicationContext.xml"})

@Runwith(SpringJUnit4ClassRunner.class)

public class customerDaoImplTest{


}