ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

java-如何在Redis 1.6.2.上使用Spring缓存管理器

2019-10-27 15:19:06  阅读:244  来源: 互联网

标签:spring-cache spring-data-redis spring-data spring java


我们正在使用Spring Cache Manager和spring-data-redis 1.5.2.这些天,我们想将spring-data-redis升级到最新版本,即:1.6.2.RELEASE.

出于某种奇怪的原因,一切都适用于1.5.2,但是升级到1.6.2后,

org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name ‘cacheManager’ defined in ServletContext
resource [/WEB-INF/spring-cache.xml]: Unsatisfied dependency
expressed through constructor argument with index 0 of type
[org.springframework.data.redis.core.RedisOperations]: Ambiguous
constructor argument types – did you specify the correct bean
references as constructor arguments?

此消息似乎是一个错误,因为redisTemplate是实现RedisOperations的RedisTemplate.

知道如何解决吗?

压力

请注意,在删除缓存配置时,1.6.2版本似乎运行良好.所以问题出在缓存上.

组态

web.xml

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/spring-redis.xml
    /WEB-INF/spring-cache.xml 
    </param-value>
</context-param>

spring-redis.xml

<context:annotation-config />
    <bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration" />

    <bean
        class="org.springframework.security.web.session.HttpSessionEventPublisher" />

    <!-- end of seesion managment configuration -->

    <bean id="redisConnectionFactory"
        class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <property name="port" value="${app.redis.port}" />
        <property name="hostName" value="${app.redis.hostname}" />
        <property name="password" value="${app.redis.password}" />
        <property name="usePool" value="true" />
    </bean>

    <!-- for publishing string over redis channels -->
    <bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
        <property name="connectionFactory" ref="redisConnectionFactory" />
    </bean>

    <!-- for storing object into redis key,value -->
    <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
        <property name="connectionFactory" ref="redisConnectionFactory" />
    </bean>

spring-cache.xml

<!-- This file must load after spring-redis.xml -->
 <cache:annotation-driven /> 

<!-- declare Redis Cache Manager -->
<bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager"
    c:template-ref="redisTemplate" />
</beans>

解决方法:

该错误的原因似乎是RedisCacheManager具有两个构造函数.他们两个都有RedisOperations作为参数.由于某种原因,Spring无法理解其与第一个构造函数而不是第二个构造函数的关系.解决方法是提及构造函数-arg索引

<bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager">
        <constructor-arg index="0" ref="redisTemplate"></constructor-arg>
</bean>

标签:spring-cache,spring-data-redis,spring-data,spring,java
来源: https://codeday.me/bug/20191027/1945226.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有