DefaultSerializer 需要可序列化的有效负载,但收到了 [org.springframework.http.ResponseEntity] 类型的对象

问题描述 投票:0回答:2

我想将List缓存到redis中。以下是相同的服务方法:-

@Autowired
private RedisTemplate<String, Object> redisTemplate;

@Cacheable(value = "notes", key = "#userId")
public ResponseEntity<?> getAllNotes(Integer userId) {

        HashOperations<String, String, Object> hashOperations = redisTemplate.opsForHash();
        //Check if the cacheKey contains this userId
        if (hashOperations.hasKey(cacheKey, userIdAsKey)) {
            List<NoteResponse> noteResponses = (List<NoteResponse>) hashOperations.get(cacheKey, userIdAsKey);
            return ResponseEntity.ok(noteResponses);
        }

        List<Note> notes = noteRepository.findAllByUserId(userId);
        List<NoteResponse> noteResponses = Helper.getNoteResponse(notes);
        hashOperations.put(cacheKey, userIdAsKey, noteResponses);
        return ResponseEntity.ok(noteResponses);
}

但我收到此异常:java.lang.IllegalArgumentException:DefaultSerializer需要可序列化的有效负载,但收到了[org.springframework.http.ResponseEntity]类型的对象

java spring-boot caching redis spring-data-redis
2个回答
1
投票
例如,

implements Serialized 添加到 NoteResponse 的末尾

公共类 NoteResponse 实现 Serialized


0
投票

我在这里有同样的问题 --> https://github.com/hendisantika/spring-data-redis-sample

还没找到解决办法。

© www.soinside.com 2019 - 2024. All rights reserved.