/** 1 把applicationContext.xml放到classpath目录下*/// Resource resource = new ClassPathResource("applicationContext.xml");// BeanFactory factory = new XmlBeanFactory(resource);// JdbcTemplate jt = (JdbcTemplate)factory.getBean("jdbcTemplate"); /** 2*/// WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(ctx);// JdbcTemplate jt = (JdbcTemplate) wac.getBean("jdbcTemplate"); /** 3*/// ApplicationContext ac = new FileSystemXmlApplicationContext("D://apache-tomcat-6.0.29//webapps//jf_shop//WEB-INF//applicationContext.xml");// JdbcTemplate jt = (JdbcTemplate) ac.getBean("jdbcTemplate"); /** 4*/// WebApplicationContext wac = (WebApplicationContext)ctx.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); // JdbcTemplate jt = (JdbcTemplate) wac.getBean("jdbcTemplate"); /** 5把applicationContext.xml放到classpath目录下*/// ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext_ty.xml"); ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext(new String[] {"applicationContext_ty.xml","applicationContext.xml","applicationContext_zj.xml","applicationContext_mtb.xml","applicationContext_wll.xml"}); BeanFactory factory = ac; JdbcTemplate jt = (JdbcTemplate)factory.getBean("jdbcTemplate");// dao = (PingPaiDao)factory.getBean("dao"); /** 6 必须继承MultiActionController类*/// JdbcTemplate jt = (JdbcTemplate) getApplicationContext().getBean("jdbcTemplate"); /** 7*/// XmlWebApplicationContext xctx = new XmlWebApplicationContext();// xctx.setConfigLocations(new String[] {"/WEB-INF/applicationContext.xml"});// xctx.setServletContext(ctx);// xctx.refresh(); /** 8*/// JdbcTemplate jt = (JdbcTemplate)xctx.getBean("jdbcTemplate");