springboot canche 无法避免Null key错误, Null key returned for cache operation

bash 复制代码
2025-12-25 14:32:08.245 [http-nio-8080-exec-2] ERROR c.c.f.a.common.exception.ArchExceptionHandler - Null key returned for cache operation (maybe you are using named params on classes without debug info?) Builder[public java.lang.String com.software.framework.arch.appliation.AbstarctSystemApplication.getAllCompanyById(java.lang.String)] caches=[arch-base_getAllCompanyById_] | key='#p0' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='#p0!=null||#p0!=''' | unless='#result=='未查询到组织信息'||#result == null ' | sync='false'
java.lang.IllegalArgumentException: Null key returned for cache operation (maybe you are using named params on classes without debug info?) Builder[public java.lang.String com.software.framework.arch.appliation.AbstarctSystemApplication.getAllCompanyById(java.lang.String)] caches=[arch-base_getAllCompanyById_] | key='#p0' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='#p0!=null||#p0!=''' | unless='#result=='未查询到组织信息'||#result == null ' | sync='false'
	at org.springframework.cache.interceptor.CacheAspectSupport.generateKey(CacheAspectSupport.java:578)
	at org.springframework.cache.interceptor.CacheAspectSupport.findCachedItem(CacheAspectSupport.java:518)
	at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:401)
	at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:345)
	at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)

springboot canche 无法避免Null key

md,真的还有人在2025年还用springboot 2.3.0吗??

springboot 2.3.0 版本的陈旧bug

在 Spring Framework < 5.3.0(即 Spring Boot < 2.4.0)中:

condition 表达式是在 key 生成之后才被评估的!

这与官方文档描述和开发者预期 完全相反!

也就是说,即使你写了:

java 复制代码
@Cacheable(key = "#p0", condition = "#p0 != null")

Spring 2.3.0 的执行顺序仍然是:

先解析 key = "#p0" → 如果 p0 == null,得到 null

立即抛出 Null key returned 异常

❌ 根本不会去检查 condition!

📌 这是一个 设计/实现 bug,在后续版本中被修复。

相关推荐
耳冉鹅几秒前
Go无锁共享内存环形缓冲区设计
开发语言·golang
⑩-10 分钟前
RabbitMQ 架构和工作原理?RabbitMQ 延迟队列如何实现?
java·分布式·架构·rabbitmq
计算机安禾10 分钟前
【C语言程序设计】第36篇:二进制文件的读写
c语言·开发语言·c++·算法·github·visual studio code·visual studio
子非鱼@Itfuture12 分钟前
try-catch和try-with-resources区别是什么?try{}catch(){}和try(){}catch(){}有什么好处?
java·开发语言
Amumu1213822 分钟前
Js:内置对象
开发语言·前端·javascript
2301_8073671924 分钟前
C++代码风格检查工具
开发语言·c++·算法
飞Link27 分钟前
具身智能音频处理核心框架 PyAudio 深度拆解与实战
开发语言·python·音视频
皙然29 分钟前
深度解析 JVM 方法区:从永久代到元空间的核心逻辑
开发语言·jvm
博语小屋29 分钟前
多路转接select、poll
开发语言·网络·c++·php
沐知全栈开发30 分钟前
C# 预处理器指令
开发语言