我试图使用Spring EL在List上使用size属性,这是抛出无法找到大小的异常.
@Cacheable(value = "cache", unless = "#result.size > 0")
public List getResult();
例外:
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)
解决方法:
size解析为List#getSize(),它不存在.尝试使用size(),如下所示:
@Cacheable(value = "cache", unless = "#result.size() > 0")
public List getResult();
标签:java,spring,expression
来源: https://codeday.me/bug/20190725/1529316.html