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>From my code: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()); } }
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" />Can anyone explain why this won't work, I've tried it with and without the @qualifier and its the sameCode:@Autowired @Qualifier("redisTemplate") private ListOperations<String, String> listOperations;
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)}


Reply With Quote
