Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Autowiring RedisTemplate as List/ValueOperations

  1. #1

    Default Autowiring RedisTemplate as List/ValueOperations

    I have run into this in the past couple months and just ran into again and have not been able to find an explanation for the problem I keep having when autowiring the RedisTemplate as one of the Operations mechanisms. Essentially, it blows up on server startup and claims that no qualifying bean for ValueOperations or ListOperations can be found. My issue with this is the Spring Redis documentation claims that this is supported. The work around is fine, but it would seem I should not need a work around.

    From the documentation:
    HTML Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:p="http://www.springframework.org/schema/p"
      xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
        
      <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
            p:use-pool="true"/>
      
      <!-- redis template definition -->
      <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
        p:connection-factory-ref="jedisConnectionFactory"/>
    
      ... 
    </beans>
    Code:
    public class Example {
    
      // inject the actual template 
      @Autowired
      private RedisTemplate<String, String> template;
    
      // inject the template as ListOperations
      @Autowired
      private ListOperations<String, String> listOps;
    
      public void addLink(String userId, URL url) {
        listOps.leftPush(userId, url.toExternalForm());
      }
    }
    From my code:
    HTML Code:
    <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" />
    <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connectionFactory-ref="jedisConnectionFactory" />
    Code:
    @Autowired 
    @Qualifier("redisTemplate")
    private ListOperations<String, String> listOperations;
    Can anyone explain why this won't work, I've tried it with and without the @qualifier and its the same

    This is the error:
    Code:
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.springframework.data.redis.core.ListOperations] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=redisTemplate)}

  2. #2
    Join Date
    Jan 2009
    Location
    Beverly Hills, CA
    Posts
    15

    Default

    <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.j edis.JedisConnectionFactory">
    <property name="hostName" value="host"/>
    <property name="port" value="6379"/>
    <!--<property name="password" value="no password"/>-->
    <property name="timeout" value="2000"/>

    </bean>

    <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTe mplate">
    <property name="connectionFactory" ref="jedisConnectionFactory"/>
    <property name="exposeConnection" value="true"/>
    </bean>

    This work perfect for me.

  3. #3

    Default whats working?

    When you said that it is working for you is that because it is starting up in the application as a bean in the context, or you are able to autowire it into a managed bean as the interface ValueOperations or ListOperations, one of the interfaces that the documentation says you can wire it in as. With the latest versions I'm still not able to wire the template in as ListOperations, and I'm not seeing any difference in your configuration vs. mine. Its what is written in section 4.4 of the spring redis docs.

    thanks

  4. #4
    Join Date
    Jan 2009
    Location
    Beverly Hills, CA
    Posts
    15

    Default

    Yeah its working perfectly fine and all operations are work pretty well. I use Value, List, Set operations.

    @Component
    public class NodeCache
    {

    @Autowired
    private RedisTemplate<String, String> template;
    private RedisList<String> nodeCache;
    private RedisAtomicLong nodeIdCounter;
    private ValueOperations<String, String> nodeValueOps;


    @PostConstruct
    public void init()
    {
    nodeValueOps = template.opsForValue();
    nodeCache = new DefaultRedisList<String>(KeyUtils.xxxx(), template);
    nodeIdCounter = new RedisAtomicLong(KeyUtils.xxxx(), template.getConnectionFactory());
    }

    public void addToNodeCache(Node node)
    {
    .......
    }
    }
    I am just working on the it ... but operations are working fine for me.

  5. #5
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Gabron, what version of spring and spring-data are you using? The issue was reported in the past and it's something related to the way the container does wiring - the latest versions of 3.x and 3.1.x in particular support this case but if you're running an older version, you might troubles.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  6. #6
    Join Date
    Jan 2009
    Location
    Beverly Hills, CA
    Posts
    15

    Default

    Spring 3.0 with spring-data-redis-1.0.0.RELEASE

  7. #7
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Can you be more specific about Spring 3.0,x? 3.0.7 is it?
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  8. #8
    Join Date
    Jan 2009
    Location
    Beverly Hills, CA
    Posts
    15

    Default

    Spring 3.0.6.RELEASE

  9. #9
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Can you try upgrading to 3.0.7.RELEASE and report back?

    Thanks,
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  10. #10

    Default

    Sorry, I had several things come up in the last week. I'm currently running 3.0.5, I will upgrade it to 3.0.7 and let you know if that fixed it.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •