Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.timpeeters:spring-boot-graceful-shutdown:2.2.2'
}
dependencies {
implementation("com.github.timpeeters:spring-boot-graceful-shutdown:2.2.2")
}
<dependency>
<groupId>com.github.timpeeters</groupId>
<artifactId>spring-boot-graceful-shutdown</artifactId>
<version>2.2.2</version>
</dependency>
libraryDependencies += "com.github.timpeeters" % "spring-boot-graceful-shutdown" % "2.2.2"
:dependencies [[com.github.timpeeters/spring-boot-graceful-shutdown "2.2.2"]]
This project adds graceful shutdown behavior to Spring Boot.
:warning: As of Spring Boot 2.3+, use the native support inside Spring Boot to accomplish graceful shutdown: https://docs.spring.io/spring-boot/docs/current/reference/html/web.html#web.graceful-shutdown. Additionally, when deployed on Kubernetes, add a preStop command: https://docs.spring.io/spring-boot/docs/current/reference/html/deployment.html#deployment.cloud.kubernetes.container-lifecycle
Multiple branches are maintained to support multiple Spring Boot versions. The following tables show the relation between the Spring Boot version and the Spring Boot Graceful Shutdown version.
| Spring Boot | Spring Boot Graceful Shutdown | Branch | | :--- | :--- | :--- | | 1.5.x | 1.0.x | 1.0.x | | 2.0.x | 2.0.x | 2.0.x | | 2.1.x | 2.1.x | 2.1.x | | 2.2.x | 2.2.x | master |
Currently this project only supports Tomcat as embedded web container for Spring Boot. Undertow and/or Jetty are not yet supported.
<dependency>
<groupId>com.github.timpeeters</groupId>
<artifactId>spring-boot-graceful-shutdown</artifactId>
<version>X.X.X</version>
</dependency>
| Key | Default value | Description | | ------------------------- | -------------- | ----------- | | graceful.shutdown.enabled | false | Indicates whether graceful shutdown is enabled or not. | | graceful.shutdown.timeout | 60s | The time to wait for active threads to finish before shutting down the Tomcat connector. | | graceful.shutdown.wait | 30s | The time to return "out of service" on the health page before starting the graceful shutdown. |
It is important to specify the time unit, otherwise you end up with milliseconds.
We found several alternatives for graceful shutdown behavior in Spring Boot.