Spring Boot’s executable JAR and WAR packaging options work across a wide range of deployment targets. This guide covers the most common production destinations and shows you the configuration each one requires.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/spring-projects/spring-boot/llms.txt
Use this file to discover all available pages before exploring further.
Deploy as a Docker container
Spring Boot integrates with Cloud Native Buildpacks (CNB) to produce optimized OCI images without writing aDockerfile. When you need more control, you can write your own Dockerfile instead.
- Buildpacks (recommended)
- Dockerfile
Buildpacks inspect your application and automatically configure layers for the JDK, your dependencies, and your application classes. The resulting image does not require Docker knowledge to produce.Maven:Gradle:Run the produced image:
Deploy to Kubernetes
Spring Boot auto-detects Kubernetes deployment environments by checking for*_SERVICE_HOST and *_SERVICE_PORT environment variables. The Actuator module exposes dedicated liveness and readiness endpoints that Kubernetes uses to manage pod lifecycle.
Add Actuator health probes
Addspring-boot-starter-actuator to your dependencies, then enable Kubernetes probes:
application.properties
Sample Kubernetes Deployment manifest
deployment.yaml
The This sleep gives the load balancer time to stop routing new requests to the pod before Spring Boot’s graceful shutdown begins.
preStop sleep hook shown above requires Kubernetes 1.32 or later. On earlier versions, use an exec command instead:Graceful shutdown configuration
Configure Spring Boot’s graceful shutdown period to match your Kubernetes termination grace period:application.properties
Deploy as a WAR to a traditional servlet container
Extend SpringBootServletInitializer
Update your main application class to extend
SpringBootServletInitializer and override configure:MyApplication.java
Mark the embedded container as provided
The embedded Tomcat (or Jetty/Undertow) must not be bundled into the WAR since the external container provides it.
- Maven
- Gradle
pom.xml
When built with the Spring Boot plugin, the WAR file is also executable via
java -jar, because lib-provided dependencies are packaged separately. You can run it on the command line and deploy it to a container with the same artifact.Install as a Linux systemd service
Running Spring Boot as a systemd service gives you automatic restart on failure, log management throughjournald, and controlled startup ordering.
Create the systemd unit file
Create
/etc/systemd/system/myapp.service:myapp.service
Customize
Description, User, Group, ExecStart, and WorkingDirectory for your application. The SuccessExitStatus=143 entry tells systemd that exit code 143 (SIGTERM) is a normal termination, not a failure.Deploy to Cloud Foundry
Cloud Foundry’s Java buildpack has first-class support for Spring Boot executable JARs. Cloud Foundry exposes service binding credentials as environment variables prefixed withvcap. Spring Boot flattens these into the Spring Environment so you can access them with standard @Value or @ConfigurationProperties bindings.
Other cloud platforms
AWS Elastic Beanstalk
AWS Elastic Beanstalk
Elastic Beanstalk supports two options for Spring Boot:
- Java SE platform — deploy an executable JAR directly. Follow the Java SE tutorial.
- Tomcat platform — deploy a WAR file. Follow the Java on Tomcat tutorial.
AWS_EXECUTION_ENV variable. Override detection with the spring.main.cloud-platform property if needed.Google App Engine Flex
Google App Engine Flex
Create an Deploy with the App Engine Maven plugin:
app.yaml in src/main/appengine/:app.yaml
pom.xml
Heroku
Heroku
Create a Deploy by pushing to the Heroku remote:
Procfile at the root of your repository that passes the $PORT environment variable: