当前位置: 首页 > 面试题库 >

spring session redis'未定义名为'springSessionRepositoryFilter'的bean'

耿炎彬
2023-03-14
问题内容

JDK1.7
Tomcat8
Redis SV 3.0
Spring3.2.14,Jedis 2.8.1,Spring Session 1.2,Spring Data Redis 1.7

[INFO ][XmlBeanDefinitionReader(loadBeanDefinitions:316)] Loading XML bean definitions 
[INFO ][DefaultListableBeanFactory(preInstantiateSingletons:603)] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@66039e85: defining beans [redisHttpSessionConfiguration,jedisPoolConfig,jedisConnectionFactory,redisTemplate]; root of factory hierarchyerere
[INFO ][ContextLoader(initWebApplicationContext:325)] Root WebApplicationContext: initialization completed in 361 ms
[ERROR][StandardContext(filterStart:4592)] Exception starting filter springSessionRepositoryFilter
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSessionRepositoryFilter' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:575)

这是我的日志。我不知道如何解决这个问题。
看起来RedisHttpSessionConfiguration bean已经创建,
为什么还没有定义filter bean?

我无法更改为spring4,因为我的公司不会让我
真正需要您的帮助,谢谢

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- redis -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
</bean>

<bean id="jedisConnectionFactory"     class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="127.0.0.1"/>
<property name="port" value="6739" />
<property name="password" value="" />
<property name="timeout" value="1800" />
<property name="poolConfig" ref="jedisPoolConfig" />
<property name="usePool" value="true" />
</bean>

<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory" />
</bean>

<!-- session redis -->
<bean id="redisHttpSessionConfiguration" class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
<property name="maxInactiveIntervalInSeconds" value="1800" />
</bean>
</beans>

这是我的配置文件,我的项目使用嵌入式tomcat,并且没有web.xml,我通过添加侦听器和过滤器

 ctx.addParameter("contextConfigLocation", "file:"+getHomePath()+"conf/applicationContext.xml");
      ctx.addApplicationListener(new ApplicationListener("org.springframework.web.context.ContextLoaderListener",true));
      ctx.addApplicationListener(new ApplicationListener("org.springframework.web.context.request.RequestContextListener",true));



    org.apache.tomcat.util.descriptor.web.FilterDefspringSessionRepositoryFilterDef =new org.apache.tomcat.util.descriptor.web.FilterDef();
    org.apache.tomcat.util.descriptor.web.FilterMap springSessionRepositoryFilterMapper = new org.apache.tomcat.util.descriptor.web.FilterMap();

    springSessionRepositoryFilterDef.setFilterName("springSessionRepositoryFilter");
    springSessionRepositoryFilterDef.setFilterClass(org.springframework.web.filter.DelegatingFilterProxy.class.getCanonicalName());
    ctx.addFilterDef(springSessionRepositoryFilterDef);
    springSessionRepositoryFilterMapper.setFilterName("springSessionRepositoryFilter");
    springSessionRepositoryFilterMapper.addURLPattern("/*");
    ctx.addFilterMap(springSessionRepositoryFilterMapper);

非常感谢你


问题答案:

您需要添加<context:annotation-config/>到Spring XML配置中以启用@Configuration类的处理。

如您的日志输出中所示,RedisHttpSessionConfiguration当前仅注册为常规bean,但不处理其中的bean定义。



 类似资料:
  • 我对Spring框架非常陌生。我正在使用NetBeans作为IDE。我跟着几个教程自学。然而,我陷入了中间,不能继续前进。让我在这里分解一下我的项目: 我的项目文件夹结构如下: 有两个班;主要的一个主应用程序。java包含以下代码: 第二类文件第一页。java看起来像这样: 豆子。xml文件如下所示: 现在,我得到的错误如下: 组织。springframework。豆。工厂NoSuchBeanDe

  • 我正在尝试一个非常基本的例子。我试图查看其他堆栈溢出答案,但无法解决此问题。我是新来的这个空间,让我知道如果我遗漏了什么。 这是我的错误日志: 2017年12月11日上午8:40:20org.springframework.beans.factory.xml.XmlBean定义Reader loadBean定义信息:从类路径资源[BeanDefinition.xml]加载XML bean定义]线程

  • 我有一个简单的spring 4 WebMVC应用程序(-config),我想添加JPA。但是,当我尝试运行应用程序时(就像在Tomcat上的deloyed一样),我会发现:什么可能是错误的来源? 创建名为“index controller”的bean时出错:注入autowired依赖项失败;嵌套异常为org.springframework.beans.factory.beancreationexc

  • 尽管标题出现了,但这并不是一个哲学问题。 从未初始化的数组读取 使用错误数据 使用不可移植构造。(即内存分配的细节1) 导致具有的行为 标准没有要求产生可预测的效果 我会称之为“未定义的行为”。但也许我错过了什么(?) null null

  • 问题内容: 我正在从参考资料中学习Spring安全性。发布3.1.2.RELEASE。如前所述,我已经像这样配置了标签 security-context.xml web.xml security-servlet.xml 但是在启动应用程序时出现此异常。如果我删除安全配置,我的Spring Web应用程序可以正常工作。我在stackoverflow中也遇到了同样的问题。但是没有运气。 问题答案: 我

  • 我有一个spring data mongo存储库类 在测试配置中,我使用EnableMongoRepositories注释 原因:org.springframework.beans.factory.nosuchbeandefinitionexception:在org.springframework.beans.factory.support.defaultlistablebeanfactory.g