An eventing mechanism is a powerful tool for decoupling different components of application modules. Application level events are also useful for maintaining state changes in an application. In this article, we will create a simple application to Spring framework based eventing mechanism to publish events and listening to the events. This article presumes the working maven installation.
Let’s start by creating a simple maven project “spring-app-event-demo” by executing the following command on your terminal application:
Now we will implement IAppEventPublisher to publish our demo events. Spring has interface ApplicationEventPublisher to publish the events and ApplicationEventPublisherAware to make the spring bean aware of eventing framework. Create a class AppEventPublisher which implements interfaces ApplicationEventPublisherAware and IAppEventPublisher as: