首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

加载applicationContext资料的七种方法

2012-10-05 
加载applicationContext文件的七种方法??/** 1 把applicationContext.xml放到classpath目录下*///???? Res

加载applicationContext文件的七种方法

??/** 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");

热点排行