Dre*_*pie 3 spring spring-mvc spring-data spring-data-redis
如果使用 @Cacheable 作为返回值“ResponseEntity”,我收到序列化错误。
\n\nCaused by: org.springframework.data.redis.serializer.SerializationException: Cannot serialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type [org.springframework.http.ResponseEntity]\nRun Code Online (Sandbox Code Playgroud)\n\n演示\xef\xbc\x9a
\n\n@Controller\n@CacheConfig(cacheNames = "logs")\npublic class LogController {\n @Cacheable(key = "#id")\n @RequestMapping(value = LogConstants.LOGS_ID_PATH, method = RequestMethod.GET)\n public ResponseEntity<Log> findById(@PathVariable Long id) {\n //....\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n
缓存对象应该是Serializable但ResponseEntity不是Serializable。
您可以在不同级别添加缓存,因此可以使返回类型可序列化或添加一些客户序列化器/反序列化器,这将能够节省ResponseEntity
| 归档时间: |
|
| 查看次数: |
13585 次 |
| 最近记录: |