与@Resource注入有关名称属性的注入困惑



我对这种依赖性注入感到困惑,作为弹簧数据redis中的一个示例:https://docs.spring.io/spring-data/data-redis/docs/current/referent/referent/html/#redis:serializer

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

考虑到重新键盘是类型重新键盘的bean,Spring如何从redistemplate bean检索ListOps?

这很有效,我主要有兴趣找到一份文档,解释了这种行为或代码处理的一件。

感谢您的帮助。

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

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);
        }
    }
}

最新更新