Spring Boot: exception while exiting application

后端 未结 1 367
暗喜
暗喜 2021-01-19 14:07

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:

相关标签:
1条回答
  • 2021-01-19 14:48

    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);    
      }
    }
    
    0 讨论(0)
提交回复
热议问题