【问题标题】:Is there any way to store response entity in redis cache?有没有办法在redis缓存中存储响应实体?
【发布时间】:2019-08-07 11:42:06
【问题描述】:

我尝试了以下代码,但出现错误 - spring web ResponseEntity 无法序列化。

org.springframework.data.redis.serializer.SerializationException:无法序列化;嵌套异常是 org.springframework.core.serializer.support.SerializationFailedException: 无法使用 DefaultSerializer 序列化对象;嵌套异常是 java.lang.IllegalArgumentException: DefaultSerializer 需要 Serializable 有效负载,但收到了 [org.springframework.http.ResponseEntity] 类型的对象

尝试了以下代码:

@Override

@Transactional

@Cacheable(value = "mostFollowedSub", key = "{#root.methodName, #offset, #limit}" )
    public ResponseEntity<Response> mostFollowedSubCategory(int offset, int limit) {
        return subCategoryDao.getMostFollowedSubCategory(offset, limit);
    }

【问题讨论】:

    标签: java spring-boot redis


    【解决方案1】:

    ResponseEntity 不是Serializable。更好的方法是在服务/DAO 层缓存(在您的情况下为getMostFollowedSubCategory 方法subCategoryDao)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-21
      • 2019-12-17
      • 1970-01-01
      • 2020-12-14
      • 2017-06-14
      • 2021-08-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多