Application lifecyclehard8+ years
How would you use Spring's application events to decouple two parts of a Boot application, and what are the tradeoffs against calling the other service directly?
Publish a plain event object through ApplicationEventPublisher (or the newer ApplicationEvent-free style — any object works as an event since Spring 4.2) and let one or more @EventListener methods react, instead of the publisher calling those consumers directly. It decouples the publisher from knowing who's listening or how many listeners there are, at the cost of making the flow harder to trace by reading code alone, and — for synchronous, same-transaction listeners — no isolation from a listener's failure unless you deliberately design for it.