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
原因是什么?
Spel 在 3.1 到 3.2 升级中受到影响,您需要向 Maven 编译器传递额外的标志以保留参数名称发现
请检查
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<parameters>true</parameters>
</configuration>