我使用的是Spring Data Redis,但官方文档让我很困惑:
<!-- redis template definition -->
<bean id="redisTemplate"
class="org.springframework.data.redis.core.RedisTemplate"
p:connection-factory-ref="jedisConnectionFactory"/>
redisTemplate
被注入ListOperations
:
// inject the template as ListOperations
@Resource(name="redisTemplate")
private ListOperations<String, String> listOps;
但RedisTemplate没有扩展ListOperations:
- public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperations<K, V>, BeanClassLoaderAware
- public class RedisAccessor implements InitializingBean
我想知道如何将redisTemplate注入到XXXOperations中。
我的spring-data-redis版本是1.8.1.RELEASE jedis版本是2.9.0
答案 0 :(得分:0)
查看此课程ListOperationsEditor
class ListOperationsEditor extends PropertyEditorSupport {
public void setValue(Object value) {
if (value instanceof RedisOperations) {
super.setValue(((RedisOperations) value).opsForList());
} else {
throw new java.lang.IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class);
}
}
}
使用PropertyEditorSupport转换类型(RedisTemplate - &gt; ListOperations)