0

org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'orderId' cannot be found on null

orderId是我订单 Vo 中的财产之一

如何在我的应用程序方法签名中使用 Spring Spring Expression Language (SpEL) @Cacheable(value = "customerId", key = "#orderVO.orderId" )

4

1 回答 1

0

异常本身说明参数对象orderVO为空。很明显,空对象没有属性。据我所知,你无法解决这个问题。

在调用该方法之前,我会确保我的 orderVO 不为空。

PS:此错误与 Redis、SpEL 或 Spring 配置无关。

编辑:为了非常简要地解释任何缓存都可以被视为 HashMap,现在想象一下当 spring 尝试缓存您的对象时,它需要一个键来将您返回的对象放在它上面。但是当您的 orderVO 为 null 时,无法获取 orderId,因此您的对象无法放入缓存(无法生成 hashkey 等)。

于 2013-12-27T11:21:10.560 回答