When implementing the ApplicationListener
interface there was an option to implement Ordered
to specify the order of invocation.
Now in Spring 4.2 there is an option to use the @EventListener
annotation. Is there a way to promise that my event listener will be called first?
Use the @Order
annotation on the @EventListener
method:
@EventListener(MyEvent.class)
@Order(10)
public void myListener() { /* ... */ }
Just as with the Ordered
interface, lower values have higher priority.
From the @EventListener
JavaDoc:
It is also possible to define the order in which listeners for a certain event are invoked. To do so, add Spring's common
@Order
annotation alongside this annotation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With