在web项目中如何启动spring容器?
2017-06-15 22:59
495 查看
1.在web.xml配置spring配置文件的信息
2.在web.xml配置spring监听
以上两种方式,一般采用第一种方式,第二种方式中ApplicationContextListener是org.springframework.web.context.ContextLoaderListener的子类。ContextLoaderListener实现ServletContextListener,读取contextConfigLocation中定义的xml文件,如果不设置contextConfigLocation的初始参数则默认会读取WEB-INF路径下的
applicationContext.xml文件。ContextLoaderListener读取这些XML文件并产生 WebApplicationContext对象,然后将这个对象放置在ServletContext的属性里,这样我们只要可以得到Servlet就可以得到WebApplicationContext对象,并利用这个对象访问spring容器管理的bean。
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:config/applicationContext-beans.xml</param-value> </context-param>
2.在web.xml配置spring监听
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
<listener> <listener-class>com.test.ApplicationContextListener</listener-class> </listener>
以上两种方式,一般采用第一种方式,第二种方式中ApplicationContextListener是org.springframework.web.context.ContextLoaderListener的子类。ContextLoaderListener实现ServletContextListener,读取contextConfigLocation中定义的xml文件,如果不设置contextConfigLocation的初始参数则默认会读取WEB-INF路径下的
applicationContext.xml文件。ContextLoaderListener读取这些XML文件并产生 WebApplicationContext对象,然后将这个对象放置在ServletContext的属性里,这样我们只要可以得到Servlet就可以得到WebApplicationContext对象,并利用这个对象访问spring容器管理的bean。
相关文章推荐
- web.xml中配置Spring容器随项目启动
- web项目启动Spring容器
- Java - 如何在Web项目中配置Spring的IoC容器?
- Spring深入挖掘:Spring在Web容器中是如何启动的
- 利用spring boot如何快速启动一个web项目详解
- web是如何启动spring容器的?
- Java - 在Web项目中如何获得Spring的IoC容器?
- WEB启动时,如何加载spring容器和struts2容器(bean的注入和url如何请求)
- web项目启动spring容器
- web是如何启动spring容器的
- web容器启动时,借助spring进行初始化操作
- Spring IoC容器在Web环境中的启动源码阅读
- Maven+Spring+MVC结构中,jetty/tomcat是如何启动项目的
- Spring源代码解析(二):IoC容器在Web容器中的启动
- .net解决方案内有多个web项目时,启动调试如何只启动一个ASP.NET Development Server?
- 复制web项目,启动的时候的工程名如何改变
- apacheFtpServer集成spring由web容器控制启动和关闭
- Spring在Web项目中的三种启动加载的配置
- spring心得2--bean的生命周期@Spring监听器的作用@Spring初始化容器案例分析@web项目使用
- Spring Ioc(1)——web中spring容器的启动初步