DEV Community

MJ
MJ

Posted on

2 1

Shutdown Spring Boot command-line application

If you have a SpringBootApplication which implements the CommandLineRunner interface and wish to terminate it after running the override run method, here is it:

@SpringBootApplication
public class DemoApplication implements CommandLineRunner {

  SpringApplication app = new SpringApplicationBuilder()
                .sources(DemoApplication.class)
                .web(false).build();

  springApplication.run(args).close();

  @Overrride
  public void run(String... strings) throws Exception {
    // Code
  }

} 

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay