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,在后续版本中被修复。

相关推荐
郝学胜-神的一滴1 小时前
Effective STL 条款09:慎重选择删除元素的方法
开发语言·网络·数据结构·c++·算法·stl
geovindu5 小时前
python:Logistic Regression
开发语言·后端·python·算法
摇滚侠6 小时前
《On Java 中文版 基础卷》阅读笔记 内部类 21
java·开发语言·笔记
番茄味城市甜菜6 小时前
二叉树刷题(C语言)
c语言·开发语言
布莱克6056 小时前
Swift 自动引用计数(ARC)详解:原理、循环引用与最佳实践
开发语言·ios·swift·arc·自动引用计数
FungLeo6 小时前
FengCMS·PHP+MySQL 升级实录 ·本地容器环境设计:只读挂载、LOCAL_UID、数据卷权限
开发语言·mysql·docker·php·fengcms
geovindu7 小时前
python: Random Forest
开发语言·后端·python·算法·随机森林
真上帝的左手7 小时前
2. 编程语言-Python-Anaconda
开发语言·python
.道阻且长.7 小时前
Linux基础IO:理解文件以及回顾C文件接口
linux·运维·服务器·c语言·开发语言·职场和发展