If I add a listener like the following to a Spring Boot application that does not use Modulith event externalization, it works and logs a few events on startup, at least LivenessState and ReadinessState:
@Bean
public ApplicationListener<?> loggingListener() {
return ApplicationListener.forPayload(event -> {
System.out.println("===== Received event=" + event.getClass().getName());
});
}
Adding event externalization, e.g., by adding a Maven dependency to spring-modulith-starter-jdbc, now causes the application to fail with a ClassCastEcxeption:
Caused by: java.lang.ClassCastException: class org.springframework.context.event.ContextRefreshedEvent cannot be cast to class org.springframework.context.PayloadApplicationEvent (org.springframework.context.event.ContextRefreshedEvent and org.springframework.context.PayloadApplicationEvent are in unnamed module of loader 'app')
at org.springframework.modulith.events.support.PersistentApplicationEventMulticaster.multicastEvent(PersistentApplicationEventMulticaster.java:146)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:448)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:381)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:1016)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:756)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:445)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
If I add a listener like the following to a Spring Boot application that does not use Modulith event externalization, it works and logs a few events on startup, at least
LivenessStateandReadinessState:Adding event externalization, e.g., by adding a Maven dependency to
spring-modulith-starter-jdbc, now causes the application to fail with aClassCastEcxeption: