我有以下代码段:
@Bean(CUSTOM_REDIS_TEMPLATE_BEAN)
public RedisTemplate<String, TransactionIdRef> redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) {
RedisTemplate<String, TransactionIdRef> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(lettuceConnectionFactory);
return redisTemplate;
}
此bean可以这样注入:
@Autowired
@Qualifier(CUSTOM_REDIS_TEMPLATE_BEAN)
private RedisTemplate<String, TransactionIdRef> redisTemplate;
@Resource(name = CUSTOM_REDIS_TEMPLATE_BEAN)
private ListOperations<String, TransactionIdRef> listOperations;
在同一个班级。我的问题是如何注入ListOperations bean而不是创建RedisTemplate bean。我提到我已经查看了Spring Data Redis代码,但没有找到可以解释其工作原理的东西。
谢谢!