Using a spring prefix to safely shutdown a break server?

This is a question about the next question How to properly close the Spring boot application?

Suppose we have a server on which 3 clients are currently connected, and each client works for a long time. Then we shut down the server using the command:

curl -X POST localhost:port/shutdown

It:

A) Let the server complete the work that 3 clients work before closing?

B) Deny any other connections so that the server eventually shuts down?

+4
source share
1 answer

Spring : org.springframework.boot.actuate.endpoint.ShutdownEndpoint, close() ApplicationContext. ...

  • beans
  • bean factory

beans , . , - " , 3 ", , . , , , .

Spring , . ContextClosedEvent beans, .., , . :

public class ShutdownListener implements ApplicationListener<ContextClosedEvent> {
    @Override
    public void onApplicationEvent(ContextClosedEvent event) {
        // 
    }
}

,

  • HTTP 503 ( - , HTTP-)
  • ,

, ApplicationListener Spring Boot, .

SpringApplicatiom app = new SpringApplication(MyApplication.class);
app.addListeners(new ShutdownListener());
+4

Source: https://habr.com/ru/post/1683774/


All Articles