我正在使用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()
}
我缓存的模型:
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
该异常的原因是谁?