SpringMvc集成redis保存session实现共享(No bean named 'springSessionRepositoryFilter' is defined)

本文介绍了一个关于Spring Session和Redis配置的问题,即当redisHttpSessionConfiguration配置放在spring-mvc.xml文件中时,会导致springSessionRepositoryFilter无法正确工作。文章详细解释了问题原因,并提供了解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

错误信息如下:

项目中包含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文件中。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值