繁体   English   中英

为什么 spring 数据 redis findById 在升级到版本 2.3.2.RELEASE 后在 Optional 中返回 null 值

[英]Why spring data redis findById returns null values in Optional after upgrading to version 2.3.2.RELEASE

spring 存储库 findById() 在 spring-data-redis 版本 2.3.1.RELEASE 上运行良好

它在 spring-data-redis 版本 2.3.2.RELEASE 上失败


这是示例存储库的链接,在 pom.xml 文件中编辑版本,然后运行,然后查看问题

https://github.com/mnguyencntt/spring-data-redis-optional


我的逻辑代码很简单:

如果找到 studentId,则返回现有的 RedisStudent object。

否则创建新的 RedisStudent 并存储在 Redis 中,返回新的 RedisStudent object。


RedisInfoController.java

    final Optional<RedisStudent> redisExisting = redisStudentRepository.findById(studentId);
    if (redisExisting.isPresent()) {
      // Spring boot 2.3.2 will print out: RedisStudent(id=null, name=null, age=null, creationTime=null)
      // Spring boot 2.3.1 will print out: RedisStudent(id=12345, name=Minh, age=28, creationTime=2020-07-28T21:31:18.318)
      log.info("{}", redisExisting.get());
      return redisExisting.get();
    }
    // Spring boot 2.3.1 will print out: Optional.empty
    log.info("{}", redisExisting);
    RedisStudent student = new RedisStudent();
    student.setId(studentId);
    student.setName("Minh");
    student.setAge("28");
    student.setCreationTime(LocalDateTime.now());
    return redisStudentRepository.save(student);

您正在运行DATAREDIS-1191 它将在 2.3.3.RELEASE 中修复

也许它与你的 controller 中的 studentId 是 null 的事实有关?

您没有在请求参数中使用 studentId。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM