1.工具类:获得ApplicationContext对象
public class SpringTest {public ApplicationContext getContext(){String conf = "applicationContext.xml";ApplicationContext ac = new ClassPathXmlApplicationContext(conf);return ac;}}
2.例子:做dao层的测试类,获取dao对象
public class TestBookDao extends SpringTest{@Testpublic void test1(){BookDao bookDao = getContext().getBean("bookDao",BookDao.class);//获得beanList<NoteBook> list = bookDao.findByUserId("48595f52-b22c-4485-9244-f4004255b972");for(NoteBook book : list){System.out.println(book.getCn_notebook_name());}}}