Spring Boot Synchronous Launcher

org.springframework.boot.loader.Launcher by default always spawns 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 an easy way to change this to execute on the same thread so that my startup service can know when the application is fully loaded, and not just with success every time.

+5
source share
1 answer

I believe that you can register a listener as follows:

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 suitable for you, you can replace ContextStartedEvent with ApplicationEvent. This is more general and will handle all context life cycle events that the application can listen to.

0
source

Source: https://habr.com/ru/post/1210125/


All Articles