Why doesn't this stream & lambda expression work with the Spel declaration?

I am trying to use Java 8 thread and lambda expression in Spring @Cache annotation.

I am trying to use the following:

@CacheEvict(value = "tags", allEntries = true, 
condition = "#entity.getTags().stream().anyMatch(tag -> tag.getId() == null)")

It does not work with:

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

However, I can make it work if I move the thread to a method for an object. Then the annotation works without errors:

@CacheEvict(value = "tags", beforeInvocation=true, allEntries = true, 
condition = "#entity.containsNewTag()")

I would prefer not to use the 'containstsNewTag () method and use the stream directly in the SpEL expression, if possible. It can be done?

+6
source share
2 answers

Spring Expression . , , . , : , , .

+5

( "")

#root - , #this .

anyMatch:

"#root.getTags().?[#this.getId() == null].size() > 0"

allMatch:

"#root.getTags().?[#this.getId() == null].size() eq #root.getTags().size()"
0

All Articles