Spring application events let one component announce that something happened and other components react without a direct dependency. You publish an event with ApplicationEventPublisher and handle it with a method annotated @EventListener. Events can be any plain Java object, listeners run synchronously by default, and you can make them asynchronous or transaction-aware when needed.
This works the same in Spring Framework 6 and 7 and in Spring Boot 3 and 4.
The ApplicationContext acts as an event bus. A publisher calls publishEvent(...), and the context delivers the event to every matching listener bean. The publisher knows nothing about the listeners, which keeps modules decoupled: an order service can publish OrderPlaced while email, inventory and analytics code each listen independently.
Since Spring 4.2 an event does not need to extend ApplicationEvent. A record is ideal because events are immutable facts.
Inject ApplicationEventPublisher through the constructor. You do not need to declare it as a bean.
The parameter type selects the events a method receives. You can add a condition with SpEL, for example @EventListener(condition = "#event.total > 100"), and order several listeners with @Order. If a listener returns a non-void value, Spring publishes it as a new event.
Listeners run on the publisher's thread by default. An exception in a listener propagates to the publisher and can abort the calling code.
Enable async processing and mark the listener with @Async so slow work does not block the caller.
On Java 21 or later with Spring Boot 3.2+, set spring.threads.virtual.enabled=true to run async work on virtual threads. Remember that an exception thrown from an async listener does not reach the publisher, so handle or log errors inside it.
When the event announces a database change, you usually want the listener to run only if the transaction commits.
Without this, an email could be sent for an order that later rolls back. By default the listener only runs when there is an active transaction. Work done in AFTER_COMMIT that needs its own database changes must start a new transaction, for example with @Transactional(propagation = Propagation.REQUIRES_NEW).
Spring and Spring Boot publish lifecycle events you can listen to, such as ContextRefreshedEvent, ContextClosedEvent, ApplicationReadyEvent and ApplicationFailedEvent.
Use ApplicationReadyEvent for start-up tasks such as cache warming instead of running them in constructors.
Yes, by default. The publisher waits for every listener to finish. Add @Async with @EnableAsync to run a listener on another thread.
No. Since Spring 4.2 any object can be an event, and records work well. Spring wraps non-ApplicationEvent objects in a PayloadApplicationEvent.
No. Spring events are in-process only and are lost if the application stops. Use Kafka, RabbitMQ or a similar broker for cross-service or durable messaging.
Check that the listener class is a Spring bean, that the parameter type matches the published event, and that any condition evaluates to true. For @TransactionalEventListener, the event must be published inside an active transaction.
Publish plain event objects with ApplicationEventPublisher and handle them with @EventListener. Use records for events, @Async for slow listeners, and @TransactionalEventListener when side effects must follow a successful commit. Spring events decouple components inside one application but are not a durable messaging system.