Spring Boot 升级 Redis - 缓存操作返回空键

问题描述 投票:0回答:1

spring 3.x升级后Redis Cache给出

Null key returned for cache operation

spring-boot版本:3.2.2

<dependency>
  <groupId>redis.clients</groupId>
  <artifactId>jedis</artifactId>
  <version>5.1.0</version>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-redis</artifactId>
  <exclusions>
    <exclusion>
      <groupId>io.lettuce</groupId>
        <artifactId>lettuce-core</artifactId>
    </exclusion>
  </exclusions>
</dependency>

可缓存方法:

@Cacheable(value = "user", key = "#username", unless = "#result == null")
public String findUsername(String username) {
    ...
}

但是如果我使用 key = "#a0" 而不是 key = "#username",问题就解决了。

@Cacheable(value = "user", key = "#a0", unless = "#result == null")
public String findUsername(String username) {
    ...
}

在之前的版本中没有必要这样做。 我以前的版本:

spring-boot version: 2.7.4
redis.clients jedis version :3.9.0

原因是什么?

spring-boot caching redis spring-data-redis jedis
1个回答
0
投票

Spel 在 3.1 到 3.2 升级中受到影响,您需要向 Maven 编译器传递额外的标志以保留参数名称发现

请检查

https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2-Release-Notes#parameter-name-discovery

https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-6.x#parameter-name-retention

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
    <parameters>true</parameters>
</configuration>
© www.soinside.com 2019 - 2024. All rights reserved.