No WebApplicationContext found: no ContextLoaderListener registered的解决方法

   <context-param>      

     <param-name>contextConfigLocation</param-name>   

 

      <param-value>classpath*:applicationContext.xml</param-value>   

 

   </context-param> 

 

我们在创建一个小工程的时候往往会碰见 No WebApplicationContext found: no ContextLoaderListener registered 这个异常  于是就在网上搜了一下 在web.xml.中加上了 这个

 <context-param>      

     <param-name>contextConfigLocation</param-name>   

 

      <param-value>classpath*:applicationContext.xml</param-value>   

 

   </context-param>

 

可是今天我加上这个也不管用了  ,于是我就再搜搜了一下  终于找到了 问题的所在 是因为spring没正常工作  在web.xml中

<servlet>
<servlet-name>SpringContextServlet </servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1 </load-on-startup>
</servlet>

 

加上这个 就好了

 

 

下面就介绍一下 :(以后有待研究)

spring中提供 ContextLoaderListenter类,用来加载context的xml文件。

spring为struts提供ContextLoaderPlugIn类,此类也可以加载context的xml文件。

区别在于,两种方式加载的WebApplicationContext,以不同的Key存放在ServletContext中。而如果你定义了HibernateFilter的话,spring会利用WebApplicationContextUtils来获取WebApplicationContext,而此类并不识别ContextLoaderPlugIn类所加载的上下文,此时便会抛出异常: No WebApplicationContext found: no ContextLoaderListener registered?

利用ContextLoaderListenter来加载dao、service级别的context,而对于struts的action,用ContextLoaderPlugIn加载。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值