0

I'm puzzled with such kind of dependency injection shown as an example in spring data 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;

Taking into consideration that redisTemplate is a bean of type RedisTemplate, how does spring manage to retrieve the listOps from the redisTemplate bean ?

This is working and I'm mainly interested to find a piece of documentation explaining this behaviour or the piece of code handling that.

Thank for your help.

aure_bobo
  • 138
  • 2
  • 8
  • Take a look into [this post](http://www.baeldung.com/spring-annotations-resource-inject-autowire) – juanlumn Sep 28 '17 at 16:54
  • 1
    It doesn't. `RedisTemplate` implements the `ListOperations` interface. – M. Deinum Sep 28 '17 at 17:58
  • RedisTemplate does not implement ListOperations. Just found the answer here : https://stackoverflow.com/questions/43006197/why-a-redistemplate-can-convert-to-a-listoperations – aure_bobo Sep 28 '17 at 19:17
  • I just found the answer here: https://stackoverflow.com/questions/43006197/why-a-redistemplate-can-convert-to-a-listoperations – aure_bobo Sep 28 '17 at 19:19

1 Answers1

0

Actually, this is working thanks to ListOperationsEditor class.

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);
        }
    }
}
aure_bobo
  • 138
  • 2
  • 8