我正在使用 Spring Boot 版本 2.1.8.RELEASE 开发 Spring Boot 应用程序。我需要构建自定义 RedisCacheManager。
RedisCacheManager 如下。
@EnableCaching
@Configuration
class CacheConfig {
@Bean
fun redisCacheManager(lettuceConnectionFactory: RedisConnectionFactory): RedisCacheManager? {
val redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofHours(1))
return RedisCacheManager.RedisCacheManagerBuilder
.fromConnectionFactory(lettuceConnectionFactory)
.cacheDefaults(redisCacheConfiguration)
.build()
}
}
在我的服务中,我使用 @Cacheble 缓存响应。看:
@Cacheable(cacheNames = ["cached_sample"])
fun getAllSample(): List<SampleRecord> {
return auditableRepository.findAll()
}
模型 I 缓存:
data class SampleRecord(
@ApiModelProperty(readOnly = true)
val id: Long? = null,
@ApiModelProperty(readOnly = true)
val active: Boolean? = null,
@ApiModelProperty(readOnly = true)
val createdDate: Instant? = null,
val param: String
): Serializable
当我第二次调用函数时,出现以下异常
引起:java.lang.ClassCastException:com.cryptocurrency.exchange.sample.model.SampleRecord 无法转换为 com.cryptocurrency.exchange.sample.model.SampleRecord
这个例外的原因是什么?