title: IllegalStateException: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@xxxxxxxx has been closed already
body: <p>After restarting a Spring Boot application using actuator, we are not able to start the application.</p>
  
  <p>We have Spring Boot application, where we want to implement a functionality where we can restart the application using actuator. Application is able to run but when we call <code>restart()</code> then it wont up and throw the exception:</p>
  
  <blockquote>
    <p>"Caused by: java.lang.IllegalStateException:
    org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1b84f475
    has been closed already"</p>
  </blockquote>
  
  <pre class="lang-java prettyprint-override"><code>    //Controller Class
      @PostMapping("/restartApp")
          public void restartUsingActuator() {
              restartService.restartApp();
          }
  
  
      //Service Class
      @Autowired private RestartEndpoint restartEndpoint;
  
          public void restartApp() {
              System.out.println("in restartApp");
  
              ConfigurableApplicationContext ctx = restartEndpoint.restart();
              ctx.refresh();
  
          }
  </code></pre>
  
  <p>Expecting to run the application.</p>