0

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

orderId is one of the property in my order's Vo

How to use Spring Spring Expression Language (SpEL) in my application Method signature @Cacheable(value = "customerId", key = "#orderVO.orderId" )

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Rajasekhar
  • 17
  • 1
  • 2

2 Answers2

1

The exception itself explains that the parameter object orderVO is null. And its obvious there would be NO property of a null object. As far as I know you cant get a way around this.

I would make sure that my orderVO is not null before calling the method.

PS : This error has nothing to do with Redis, SpEL or Spring configurations.

EDIT: To explain very briefly any cache can be treated as HashMap, now imagine when spring will try to cache your object it will need a key to put your returned object against it. But when your orderVO is null no orderId can be obtained and hence your object can not be put into cache (no hashkey can be generated, etc etc).

Anuj Patel
  • 17,261
  • 3
  • 30
  • 57
-1

The problem is that when you use SpEl with @Cacheable it uses a separate context which doesn't contain your parameter, to access the data of the same class you need to use the #root.methodName

https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/cache.html

Ion Ionets
  • 105
  • 1
  • 8