我对这种依赖注入感到困惑,如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;考虑到RedisTemplate是redisTemplate类型的bean,spring是如何从redisTemplate bean检索listOps的呢?
这是有效的,我主要感兴趣的是找到一段文档来解释这一行为或处理那段代码。
谢谢你的帮助。
发布于 2017-09-29 03:21:13
实际上,这要归功于ListOperationsEditor类。
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);
}
}
}https://stackoverflow.com/questions/46474327
复制相似问题