我试图将一个springboot应用程序连接到两个不同的redis实例:一个用作数据库,另一个仅用作缓存。我添加了不同名称的连接工厂和redis模板,并使用@限定符链接它们。我试图从自动配置中禁用类RedisAutoConfiguration,但没有任何工作。
我总是收到这个错误:
包装: org.springframework.beans.factory.UnsatisfiedDependencyException:错误创建名为'redisTemplate‘的类路径资源org/springframework/boot/autoconfigure/data/redis/RedisAutoConfiguration$RedisConfiguration.class:不满意的依赖关系,通过构造函数参数表示,org.springframework.data.redis.connection.RedisConnectionFactory:类型为0,没有定义org.springframework.data.redis.connection.RedisConnectionFactory类型的限定bean :预期的单匹配bean,但发现2: redisCacheFactory,redisJitFactory;嵌套异常为org.springframework.beans.factory.NoUniqueBeanDefinitionException:没有定义org.springframework.data.redis.connection.RedisConnectionFactory类型的限定bean :预期的单个匹配bean,但发现2: redisCacheFactory、redisJitFactory
你能给我一点提示,说明如何实现这一点吗?
提前感谢!
发布于 2016-09-30 15:00:27
问题是将connectionFactory提取为bean。如果您在模板bean中声明它,它将正常工作。以下几点对我来说是可行的:
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
p:defaultSerializer-ref="stringRedisSerializer">
<property name="connectionFactory">
<bean class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.ip}" p:port="6379" p:use-pool="true"/>
</property>
</bean>
<bean id="redisTemplate2" class="org.springframework.data.redis.core.RedisTemplate"
p:defaultSerializer-ref="stringRedisSerializer">
<property name="connectionFactory">
<bean class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.ip2}" p:port="6379" p:use-pool="true"/>
</property>
</bean>
<bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/>https://stackoverflow.com/questions/36621090
复制相似问题