【发布时间】:2015-11-14 22:04:59
【问题描述】:
我正在尝试在 Spring @Cache 注释中使用 Java 8 流和 lambda 表达式。
我正在尝试使用以下内容:
@CacheEvict(value = "tags", allEntries = true,
condition = "#entity.getTags().stream().anyMatch(tag -> tag.getId() == null)")
它失败了:
SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
org.springframework.expression.spel.SpelParseException:
EL1042E:(pos 40): Problem parsing right operand
但是,如果我将流移动到实体上的方法中,我就能让它工作。注释然后按如下方式正常工作:
@CacheEvict(value = "tags", beforeInvocation=true, allEntries = true,
condition = "#entity.containsNewTag()")
如果可能,我宁愿不需要“containtsNewTag()”方法,而是直接在 SpEL 表达式中使用流。这个可以吗?
【问题讨论】:
标签: spring spring-el spring-cache