I want to run a Spring application that should exit after it has done its work. But in my implementation I get an exception.
build.gradle
contains:
In your Application.class
you can implement CommandLineRunner
interface.
@SpringBootApplication
public class Application implements CommandLineRunner{}
After implementation you need to implement a void method run()
@Override
public void run(String... strings) {
//here starts your code (like in a normal main method in a java application)
}
The application shuts down after excecuting all of the code.
The complete Application.class
:
@SpringBootApplication
public class Application implements CommandLineRunner{
@Override
public void run(String... strings) {
//here your code...
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}