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

查了很多资料,有不同的说法,我总算是解决了

说法1:

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加载。

出现了No WebApplicationContext found: no ContextLoaderListener
registered异常,此问题产生的原因是因他的资源文件没加载进来所以找不到文件引起,于是我在web.xml中加入了如下语句:


   
  
      
  
      contextConfigLocation   
  
      classpath*:applicationContext.xml   
  
  
 
结果不起作用;

改为  
      contextConfigLocation  
      /WEB-INF/applicationContext.xml  
  

也不起作用。

说法2:

配置监听,也是没有加载到这个类,原理都一样,可能不太清楚怎么配置,也不起作用


 
   org.springframework.web.context.ContextLoaderListener
 

 

 

说法3:

看你报错应该是spring没正常工作,web.xml里要配的

SpringContextServlet

org.springframework.web.context.ContextLoaderServlet

1

ContextLoaderServlet这个类不加载的话,肯定会报 No WebApplicationContext found: no ContextLoaderListener registered


这个就能用了

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/logonin/archive/2008/07/31/2743260.aspx

你可能感兴趣的:([转]No WebApplicationContext found: no ContextLoaderListener registered的解决方法)