在web项目中如何启动spring容器?
来源:互联网 发布:益思留学 知乎 编辑:程序博客网 时间:2024/06/07 17:13
1.在web.xml配置spring配置文件的信息
<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。
阅读全文
1 0
- 在web项目中如何启动spring容器?
- Spring深入挖掘:Spring在Web容器中是如何启动的
- web项目启动Spring容器
- SpringIOC容器在Web项目中启动源码分析
- web是如何启动spring容器的?
- web是如何启动spring容器的
- spring(2) spring ioc容器在Web容器中的启动
- Spring在Web容器中的启动过程
- 【spring】IOC容器在WEB容器中的启动
- web容器启动spring容器
- web容器启动Spring
- 如何在Eclipse中第一次启动一个web项目
- 【Java.Spring.MVC】Spring在Web容器中的启动过程
- 在docker容器中部署Web项目
- 在不启动容器下,如何启动spring的机制
- 在web容器中获取spring容器对象
- 在web容器中获取spring容器中的bean对象
- 如何在filter中拿到spring容器
- Jquery实现简单的导航单并且经常使用
- Java单列集合总结
- 主题六 函数(C语言核心)----38.函数设计技巧
- 15、权限管理之文件系统属性chattr、以及sudo
- 流式计算storm,spark文章
- 在web项目中如何启动spring容器?
- CSAPP cache-lab
- AndroidClassLoader源码解析
- spring MVC 框架搭建
- [3] Centos 7.3 用户和组管理
- 单例模式
- Windows下用caffe训练自己的数据
- 【技术选型-BI】BI技术选型
- Java 课后习题汇总