转自:http://www.blogjava.net/amigoxie/archive/2007/02/16/100086.html
spring为ApplicationContext提供的3种实现分别为:ClassPathXmlApplicationContext,FileSystemXmlApplicationContext和XmlWebApplicationContext,其中XmlWebApplicationContext是专为Web工程定制的。使用举例如下:
-
FileSystemXmlApplicationContext
eg1.
ApplicationContext ctx = new FileSystemXmlApplicationContext("bean.xml"); //加载单个配置文件
eg2.
String[] locations = {"bean1.xml", "bean2.xml", "bean3.xml"};
ApplicationContext ctx = new FileSystemXmlApplicationContext(locations ); //加载单个配置文件
eg3.
ApplicationContext ctx =new FileSystemXmlApplicationContext("D:/project/bean.xml");
//根据具体路径加载文件
-
ClassPathXmlApplicationContext
eg1.
ApplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml");
eg2.
String[] locations = {"bean1.xml", "bean2.xml", "bean3.xml"};
ApplicationContext ctx = new ClassPathXmlApplication(locations);
注:其中FileSystemXmlApplicationContext和ClassPathXmlApplicationContext与BeanFactory的xml文件定位方式一样是基于路径的。
-
XmlWebApplicationContext
eg1.
ServletContext servletContext = request.getSession().getServletContext();
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
分享到:
相关推荐
NULL 博文链接:https://canfly2010.iteye.com/blog/443063
主要介绍了 Spring获取ApplicationContext对象工具类的实现方法的相关资料,希望通过本文能帮助到大家,让大家实现这样的功能,需要的朋友可以参考下
spring的Applicationcontext对事件的监听,在一个applicationContext范围内,实现类似MQ的效果
Spring中ApplicationContext加载机制
Spring中ApplicationContext和beanfactory区别.rar
spring 获得applicationcontext公用方法
Spring中ApplicationContext对事件传递
ApplicationContext及它的3种实现
NULL 博文链接:https://ylxy3058.iteye.com/blog/2223687
Spring配置文件ApplicationContext,内容齐全,有需要的可以下载。
《Spring的数据源配置文件模板》applicationContext.zip
Spring[applicationContext.xml]灵活性代理
Spring获取webapplicationcontext,applicationcontext几种方法详解
spring定时任务必须的包和spring配置说明
spring4的“所有jar包”+applicationContext.xml+web.xml====全套
spring2.5的applicationContext配置文件.
NULL 博文链接:https://mutourenoo.iteye.com/blog/1156865
Spring Web MVC开发 xml配置文件格式,无bean之类 Spring Web MVC开发配置文件 applicationContext
这个工程主要实现了: Spring中Bean的生命周期 applicationcontext的应用(实现国际化,事件的传递)