【问题标题】:Spring Cache + Spring Expression Language (SpEL) + RedisSpring Cache + Spring 表达式语言 (SpEL) + Redis
【发布时间】:2014-01-14 22:00:50
【问题描述】:

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" )

【问题讨论】:

    标签: java spring-el spelevaluationexception


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 当我停止并启动服务器时,Redis 服务器中的数据正在从数据库中丢失
    • 您是否检查了 Redis 设置以在关机时保存数据? redis.io/commands/shutdown
    • 我正在使用 linux 我的 IT 团队已经安装了它
    猜你喜欢
    • 2011-10-04
    • 1970-01-01
    • 2012-05-24
    • 2013-12-10
    • 2016-06-27
    • 2012-02-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    相关资源
    最近更新 更多