org.springframework.boot.loader.Launcher by default will always spawn a background thread in the launch() method (https://github.com/spring-projects/spring-boot/blob/master/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java#L105). Is there any easy way to change this to execute in the same thread, so my service launcher can know when the application has fully loaded, and not simply exit with success immediately every time.
5
votes
1 Answers
0
votes
I believe you can register listener like this:
public static void main(String[] args) {
SpringApplication app = new SpringApplication(WsBootClientApplication.class);
app.addListeners(new ApplicationListener<ContextStartedEvent>() {
@Override
public void onApplicationEvent(ContextStartedEvent event) {
//do your stuff
}
});
app.run(args);
}
If ContextStartedEvent is not the right event for you, you can replace ContextStartedEvent with ApplicationEvent. That is more generic and will handle all context lifecycle events your application can listen to.
Thread
so you might get into trouble if you try to change this method. What is your "service launcher" actually doing? – Phil Webb