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