Closed maciejwalkowiak closed 6 months ago
I went with the plain annotation attribute for now, as any kind of callback would require Spring's event handling adapted. Plus, a per-class condition method might not fit well with multiple listeners declared on a single class.
@ApplicationModuleListener
currently does not exposecondition
property from@TransactionalEventListener
.There are scenarios where listener is meant to handle event only if this event meets certain criteria. For example
With code like above, there is an unnecessary insert & update into
EVENT_PUBLICATION
table - which ideally could be avoided. This can be achieved by not using@ApplicationModuleListener
and falling back to@TransactionalEventListener
:A quick win would be to just add
condition
property to@ApplicationModuleListener
allowing following:As a side note, perhaps there could be a way to implement a method like
boolean supports(T event)
on the listener class that would be invoked for each published event, before event publication is registered. I think it would be more elegant than using SPEL.