首页 > 解决方案 > 带有 kotlin 的 Spring Data Redis 在 2.3.2.RELEASE 版本中中断

问题描述

将 Spring Boot 从 2.3.0 迁移到 2.3.2.RELEASE 后,我的 @RedisHash 代码已损坏。

@RedisHash(value = "OtpCache", timeToLive = 5 * 60)
data class OtpCache(@Id val mobile: String,
                        val otp: String)


interface OtpCacheRepository : CrudRepository<OtpCache, String>

val optional = otpCacheRepository.findById("unknown")
println("optional = " + optional.isPresent)

当我尝试使用 查找具有未知标识符的 OtpCache 实例findById而不是获取 Optional.empty() 时,我看到了一个异常

Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method com.example.demo.OtpCache.<init>, parameter mobile
at com.example.demo.OtpCache.<init>(DemoApplication.kt) ~[main/:na]
at com.example.demo.OtpCache_Instantiator_humu2e.newInstance(Unknown Source) ~[main/:na]
at org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator$EntityInstantiatorAdapter.createInstance(ClassGeneratingEntityInstantiator.java:238) ~[spring-data-commons-2.3.2.RELEASE.jar:2.3.2.RELEASE]

这段代码在 Spring Boot 中运行良好2.3.0.RELEASE

我正在使用 Kotlin 数据类在我的代码库中创建 POJO。

这是示例存储库的链接

https://github.com/cancerian0684/bug-reishash-springboot

标签: spring-bootspring-data-redis

解决方案


推荐阅读