ContextStartedEvent not broadcast on Spring Download

I port the application to Spring boot. My application is listening ContextStartedEvent, but it looks like Spring boot is not generating such an event. I can change my application and listen ApplicationReadyEvent, but according to the spring boot document , the "old" events are still emitted.

I would like to keep my code intact as much as possible.

Question: is ContextStartedEvent supported using Spring boot or not?

Demo:

@EnableAutoConfiguration
public class EventExample {

    @EventListener(classes = ContextStartedEvent.class)
    void start() { System.out.println("Listen ContextStartedEvent");} //not called

    @EventListener(classes = ApplicationReadyEvent.class) 
    void start2(){System.out.println("Listen ApplicationReadyEvent");} //called

    public static void main(String[] args) throws Exception {
        SpringApplication.run(EventExample.class, args);
    }
}

Exit

Listen to ApplicationReadyEvent

0
source share
1 answer

ContextStartedEvent ApplicationContext.start(). SpringApplication.run() start(), refresh(). ContextStartedEvent, . :

public static void main(String[] args) throws Exception {
    SpringApplication.run(EventExample.class, args).start();
}
+2

All Articles