I am trying to publish a custom event in Spring MVC, but is is not firing while context is loading, below are the code snippet,
The onConnectionOpened will be called after connecting to a server which is triggered after bean initialization using @PostConstruct
@Autowired
private ApplicationEventPublisher publisher;
public void onConnectionOpened(EventObject event) {
publisher.publishEvent(new StateEvent("ConnectionOpened", event));
}
I am using annotation in listener part as below
@EventListener
public void handleConnectionState(StateEvent event) {
System.out.println(event);
}
I am able to see events fired after the context is loaded or refreshed, is this expected that custom application events can be published after the context loaded or refreshed?.
I am using Spring 4.3.10
Thanks in advance