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{
}