Search code examples
javaspringspring-bootdesign-principleshexagonal-architecture

Spring application events without extending ApplicationEvent


Is there any way to define custom application events without extending ApplicationEvent? We are having submodules based on ports and adapters principle, domain module not having any any external dependencies like spring-context. And application module can have Spring dependency and EventListener and EventPublisher classes.

Event classes seems domain specific, and should be defined independent of any framework. But with current Spring's approach for defining events, we have to depend on spring-context. Any alternatives?


Solution

  • You can publish whatever you like with the [ApplicationEventPublisher]. This has been the case since Spring 4.2 which saw the introduction of @EventListener. Since then you don't need to extend ApplicationEvent anymore.

    Hence your knowledge was/is outdated.