No bean named 'springSessionRepositoryFilter' is defined

由于配置用了第一种,所以会去找 applicationContext.xml,但项目中又没有 applicationContext.xml,所以报这个错误
 
解决:
吧web.xml中的去掉
<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


 

web.xml加载spring配置文件的方式主要依据该配置文件的名称和存放的位置不同来区别,目前主要有两种方式。

1.如果spring配置文件的名称为applicationContext.xml,并且存放在WEB-INF/目录下,那么只需要在web.xml中加入以下代码即可

<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

该监听器会自动扫描WEB-INF/ 下的applicationContext.xrnl 文件,这种方式多数用在只有一个配置文件的情况下。
还可以使用Spring的ContextLoaderServlet的这个特殊Servlet,实现代码如下

<servlet>
  <servlet-name>context</servlet-name>
  <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-name>
  <load-on-startup>1(比较小的数字就可以)</load-on-startup>
</servlet>

猜你喜欢

转载自m635674608.iteye.com/blog/2398941