16cha 16cha - 2 years ago 71
Java Question

How can I catch " - Started abcApplication in 12.49 seconds " event?

Language:Java, Framework:Springboot, application-name:abcApplication
"21:47:32.133 [main] INFO c.c.abc.abcApplication - Started abcApplication in 12.49 seconds (JVM running for 8.467)"

I am developing a web application with Springboot.
The springboot-application outputs the above message when the application starts up successfully. How can I handle this event? I would like to do something when the application's initialization is completed.

Answer Source

What you are looking for is ContextRefreshedEvent, you can create a class and make it component and implement ApplicationListener

@Component
public class ServerReadyClass implements  ApplicationListener<ContextRefreshedEvent> {

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        //YOUR LOGIC
    }
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download