《1》在独立应用程序中,获取ApplicationContext:
AbstractApplicationContext context = new ClassPathXmlApplicationContext("");
();//释放资源
《2》在web环境中,获取ApplicationContext:
A)ServletContext servletContext = ().getServletContext();
ApplicationContext context = (servletContext);
B)String contextpath = "";
WebApplicationContext context = ().getServletContext().getAttribute(contextpath);
二、不提倡的方法:(这种写法不仅仅耗内存,占资源,而且如果数据库连接太多,很容易造成系统运行的缓慢甚至stop!)
ApplicationContext context = new ClassPathXmlApplicationContext("");