https://stackoverflow.com/a/54762909/4026629 is a nice idea, but seems unnecessarily verbose, and it can be simplified for most use cases.
Adding this line in one's main application class:
new CountDownLatch(1).await();
e.g.
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(DemoApplication.class, args);
new CountDownLatch(1).await();
}
seems to do the trick.