Spring Boot instance code exits safely through the interface

  • 2020-10-07 18:42:29
  • OfStack

1. Introduce actuator and security dependence into ES1en. xml


    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

2. Open shutdown endpoint in application. properties (default: off)


# open shutdown
endpoints.shutdown.enabled=true
# The custom api address 
endpoints.shutdown.path=/shutdown

3. Turn on password authentication

Turn on password authentication for the /admin directory.


endpoints.shutdown.sensitive=true
security.basic.enabled=true
security.basic.path=/admin
security.user.name=admin
security.user.password=test
management.security.roles=SUPERUSER
management.port=19888
management.context-path=/admin
management.security.enabled=true

4. Send the request to close HTTP


curl -u "admin:test" -X POST http://127.0.0.1:19888/admin/shutdown

5. Return content


{
  "message": "Shutting down, bye..."
}

conclusion


Related articles: