spring eventListener with external condition

Viewed 8079

I need a flexible filters for FooEvents for multiple EventListeners all over my code. I can use @EventListener(condition="event.enabled"), but my filters require many attributes of fooEvent to be analysed.

I was hoping that I could use a Predicate-Bean from my Application Context:

@Component
public class FooPredicate implements Predicate<FooEvent> {
   public boolean test(FooEvent event) {...}
}

...

@EventListener(condition="${fooPredicate.test(event)}")
public void handle(FooEvent event) { ... }

But I get:

org.springframework.expression.spel.SpelEvaluationException: EL1011E: 
   Method call: Attempted to call method 
   test(org.springframework.context.PayloadApplicationEvent) on null 
   context object

Is it possible to use external, complex conditions for EventListerns? Or at least to define global listeners with complex conditions and inherit their behavior without repeating the full conditions?

1 Answers
Related