SpringMvc集成redis保存session实现共享(No bean named 'springSessionRepositoryFilter' is defined)
错误信息如下:
项目中包含spring.xml和spring-mvc.xml文件,将redisHttpSessionConfiguration的配置信息
<!-- spring session start... --> <!-- Put session into redis 1800秒 30分钟--> <bean id="redisHttpSessionConfiguration" class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"> <property name="maxInactiveIntervalInSeconds" value="18000" /> <property name="cookieSerializer" ref="defaultCookieSerializer"/> </bean> <!-- 设置Cookie domain 和 名称 --> <bean id="defaultCookieSerializer" class="org.springframework.session.web.http.DefaultCookieSerializer"> <!-- <property name="domainName" value="${session.domain}"/> --> <property name="cookieName" value="SESSION"/> <property name="cookiePath" value="/" /> <!-- <property name="domainNamePattern" value="^.+?\.(\w+\.[a-z]+)$"></property> --> </bean>写在spring-mvc.xml文件中。项目web.xml的扫描顺序是spring.xml,然后再进入spring-mvc文件。由于在web.xml中配置了
<filter> <filter-name>springSessionRepositoryFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSessionRepositoryFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>ERROR</dispatcher>
</filter-mapping>
而
springSessionRepositoryFilter需要用到redisHttpSessionConfiguration的相关配置,此时为扫描,所以导致错误。解决方案:将
redisHttpSessionConfiguration的配置改在spring.xml文件中。