Spring Expression Language - Size Property in List

I am trying to use a property size

on a list using Spring EL that is throwing an exception whose size cannot be found.

@Cacheable(value = "cache", unless = "#result.size > 0")
public List<Results> getResult();

      

An exception:

org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 8): Field or property 'size' cannot be found on object of type 'java.util.ArrayList'
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:217)
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85)
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:43)
        at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:346)
        at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:84)

      

+3


source to share


2 answers


size

resolves List#getSize()

that doesn't exist. Try size()

this way:



@Cacheable(value = "cache", unless = "#result.size() > 0")
public List<Results> getResult();

      

+4


source


As with the error, size is not a property of the ArrayList, it is a function. Trysize()



+3


source







All Articles