Я разрабатываю приложение Spring Boot с версией Spring Boot 2.1.8.RELEASE. Мне нужно собрать пользовательский 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
Что может быть причиной этого исключения?