使用名称属性

时间:2017-09-28 16:42:44

标签: spring spring-boot spring-data-redis

我对在spring数据redis中作为示例显示的这种依赖注入感到困惑: https://docs.spring.io/spring-data/data-redis/docs/current/reference/html/#redis:serializer

  // inject the template as ListOperations
  @Resource(name="redisTemplate")
  private ListOperations<String, String> listOps;

考虑到redisTemplate是RedisTemplate类型的bean,spring如何管理从redisTemplate bean中检索listOps?

这是有效的,我主要想找到解释此行为的文档或处理该行为的代码片段。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

实际上,这要归功于ListOperationsEditor类。

class ListOperationsEditor extends PropertyEditorSupport {
    ListOperationsEditor() {
    }

    public void setValue(Object value) {
        if(value instanceof RedisOperations) {
            super.setValue(((RedisOperations)value).opsForList());
        } else {
            throw new IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class);
        }
    }
}