2
我需要一个灵活的筛选器FooEvents
多个EventListeners遍及我的代码。 我可以使用@EventListener(condition =“event.enabled”),但我的过滤器需要fooEvent的许多属性进行分析。春季eventListener与外部条件
我希望我可以从我的应用程序上下文使用谓词豆:
@Component
public class FooPredicate implements Predicate<FooEvent> {
public boolean test(FooEvent event) {...}
}
...
@EventListener(condition="${fooPredicate.test(event)}")
public void handle(FooEvent event) { ... }
,但我得到:
org.springframework.expression.spel.SpelEvaluationException: EL1011E:
Method call: Attempted to call method
test(org.springframework.context.PayloadApplicationEvent) on null
context object
是否可以使用外部的,复杂的条件EventListerns?或者至少要定义具有复杂条件的全球听众并在不重复全部条件的情况下继承他们的行为?