I have several services that are listening for Spring events to make changes to my underlying data model. These all work by implementing ApplicationListener<Foo>
. Once all of the Foo
listeners modify the underlying data model, my user interface needs to refresh to reflect the changes (think fireTableDataChanged()
).
Is there any way to ensure that a specific listener for Foo
is always last? Or is there any way to call a function when all other listeners are done? I'm using annotation based wiring and Java config, if that matters.
Best Answer
All your beans implementing
ApplicationListener
should also implementOrdered
and provide reasonable order value. The lower the value, the sooner your listener will be invoked:Moreover you can implement
PriorityOrdered
to make sure one of your listeners is always invoked first.