【发布时间】:2020-07-28 10:31:15
【问题描述】:
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 对象。
否则在 Redis 中创建新的 RedisStudent 并存储,返回新的 RedisStudent 对象。
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);
【问题讨论】:
-
好的,请问有什么问题?
-
更新了主题@aBnormaLz
-
更新了 spring boot 版本 2.3.3.RELEASE,现在已经修复并且可以完美运行。 github.com/mnguyencntt/spring-data-redis-optional
标签: java spring-boot spring-data-jpa spring-data-redis