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 生成之后才被评估的!

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

也就是说,即使你写了:

@Cacheable(key = "#p0", condition = "#p0 != null")

Spring 2.3.0 的执行顺序仍然是:
先解析 key = “#p0” → 如果 p0 == null,得到 null
立即抛出 Null key returned 异常
❌ 根本不会去检查 condition!
📌 这是一个 设计/实现 bug,在后续版本中被修复。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐