Spring application events without extending ApplicationEvent

418 Views Asked by At

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?

1

There are 1 best solutions below

0
M. Deinum On BEST ANSWER

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.