Skip to main content

Application Events: Publishing and Listening

Learn Application Events: Publishing and Listening (Phase 9 · Spring Events (Core), Spring Core) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

The event model • Spring's event mechanism is an in-process publish/subscribe (Observer pattern) built on ApplicationEventPublisher and ApplicationEventMulticaster . Publishers do not know listeners: loose coupling between modules (order → notification, audit, search indexing). Events can be any object since Spring 4.2 (no need to extend ApplicationEvent ); using records is idiomatic. • Publish : inject ApplicationEventPublisher and call publishEvent(event) . Listen : @EventListener method (parameter type selects the event; supports polymorphism and generics) or ApplicationListener<E> . By...

More lessons in Phase 9 · Spring Events (Core)