简体   繁体   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 repository findById() is working fine on spring-data-redis version 2.3.1.RELEASE spring 存储库 findById() 在 spring-data-redis 版本 2.3.1.RELEASE 上运行良好

its failed on spring-data-redis version 2.3.2.RELEASE它在 spring-data-redis 版本 2.3.2.RELEASE 上失败


Here is link to sample repository, edit version in pom.xml file, then run, then see the issue这是示例存储库的链接,在 pom.xml 文件中编辑版本,然后运行,然后查看问题

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


My logic code is very simple:我的逻辑代码很简单:

if studentId found, return existing RedisStudent object.如果找到 studentId,则返回现有的 RedisStudent object。

else create new RedisStudent & store in Redis, return new RedisStudent object.否则创建新的 RedisStudent 并存储在 Redis 中,返回新的 RedisStudent object。


RedisInfoController.java 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);

You are running into DATAREDIS-1191 .您正在运行DATAREDIS-1191 It will be fixed in the 2.3.3.RELEASE .它将在 2.3.3.RELEASE 中修复

Maybe it has something to do the fact that studentId is null in your controller?也许它与你的 controller 中的 studentId 是 null 的事实有关?

You are not taking studentId in the request param.您没有在请求参数中使用 studentId。

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

相关问题 将 spring 从 2.2.2 升级到 2.3.2.RELEASE 时出错 - Getting error when upgrading spring boot from 2.2.2 to 2.3.2.RELEASE Spring Data JPA findById()方法返回null而不是Empty可选 - Spring Data JPA findById() method returning null instead of Empty Optional Spring 数据 findById 返回缓存值而不是数据库一 - Spring Data findById returns cached value instead of database one CrudRepository findById 返回 null mysql - CrudRepository findById returns null mysql 为什么“findById()”在同一实体上调用 getOne() 后返回代理? - Why “findById()” returns proxy after calling getOne() on same entity? Spring Data findById(HashKey)挂起 - Spring Data findById (HashKey) hang 测试 JpaRepository findById 为 UUID 返回 null - Test JpaRepository findById returns null for UUID JUnit FindById 返回空指针(Mockito) - JUnit FindById returns null pointer (Mockito) 升级到 Spring boot 2.3.5.RELEASE 后的 Cassandra 身份验证问题 - Cassandra authentication issue after upgrading to Spring boot 2.3.5.RELEASE 从Spring Data JPA 1.4.x升级到更新的版本(例如1.7.1)后,为什么我的中间存储库接口会引起麻烦? - Why does my intermediate repository interface cause trouble after upgrading from Spring Data JPA 1.4.x to a more recent version (e.g. 1.7.1)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM