无效对象当前不属于此池

时间:2017-09-20 15:26:40

标签: spring-data-redis

当我使用redisCacheManager来放置东西时,它会抛出异常“Invalidated object not the this of this pool”。但是当我将usePool设置为false时,它可以工作。我认为这是一个多线程案例。但我不知道为什么spring-data-redis的注释可以工作。

<code>
 ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/applicationContext.xml");
        UserServiceImpl userService = applicationContext.getBean(UserServiceImpl.class);
        RedisCacheManager redisCacheManager = applicationContext.getBean(RedisCacheManager.class);
        redisCacheManager.getCache("cacheName").put("key","value");

    <cache:annotation-driven ></cache:annotation-driven>
    <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
          p:connection-factory-ref="jedisConnectionFactory"/>
    <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <property name="usePool" value="true"></property>
        <property name="hostName" value="${redis.host}" />
        <property name="port" value="${redis.port}" />
    </bean>
    <bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager"
          c:template-ref="redisTemplate"/>
</code>

0 个答案:

没有答案