使用WebApplicationContextUtils.getWebApplicationContext(ServletContext cn)获取WebApplicationContext为null
来源:互联网 发布:淘宝买家怎么用淘宝客 编辑:程序博客网 时间:2024/06/05 09:05
在使用SpringMVC搭建demo时再使用WebApplicationContextUtils.getWebApplicationContext(ServletContext cn )方法获取WebApplicationContext对象时获取到的是空,可能的原因是因为在Web.xml中没有配置ContextLoaderListener监听或者没有配置ContextLoaderServlet的Servlet的类。
原理:服务器在启动时会读取Web.xml中的配置的监听,而ContextLoaderListener这个监听类的职责就是自动封装WebApplicationContext对象,由于没有配置该监听所有获取到对象是null。
解决方案:
在Web.xml中配置以下监听:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
阅读全文
0 0
- 使用WebApplicationContextUtils.getWebApplicationContext(ServletContext cn)获取WebApplicationContext为null
- 通过 ServletContext 获取 WebApplicationContext
- Spring获取WebApplicationContext为null解决方案
- Spring 中获取servletContext及WebApplicationContext
- Spring 中获取servletContext及WebApplicationContext
- Spring 中获取servletContext及WebApplicationContext
- Spring 中获取servletContext及WebApplicationContext
- Struts2框架中WebApplicationContextUtils.getWebApplicationContext(event.getServletContext())的值
- 使用WebApplicationContext 获取文件内容
- webApplicationContext 与servletContext
- webApplicationContext 与servletContext
- webApplicationContext 与servletContext详解
- webApplicationContext 与servletContext
- webApplicationContext 与servletContext
- webApplicationContext 与servletContext
- idea 中 ServletContext.getRealPath 为 null
- WebApplicationContextUtils
- WebApplicationContextUtils
- Python 中的一些坑
- 类型转换关键字
- 笔记-NopCommerce系统架构分析-任务机制
- hive 之 order by,sort by, distribute by, cluster by 区别
- WAMP下redis的安装与使用
- 使用WebApplicationContextUtils.getWebApplicationContext(ServletContext cn)获取WebApplicationContext为null
- jquery datatable调用.clear().draw()方法后不能清空表格数据
- 我的第一次h5 五子棋游戏作品
- google的glog日志管理
- 剑指offer面试题15 链表中倒数第K个结点
- 数据结构与算法(java)——链表
- 频道循环,每个子栏目下,自动加广告位
- 如何给100亿个数字排序?
- Linux更换默认软件源