Deploying Spring Boot Apps
Java/Kotlin enterprise apps as self-contained JARs, deploy to JVM container, Cloud Foundry, or Kubernetes.
PlatformsAdvanced
Why
Spring Boot's executable JAR with embedded Tomcat eliminates external app server setup. The Spring ecosystem (Security, Data, Cloud) provides everything enterprise apps need with auto-configuration.
Platform-as-a-Service adoption grew 24% in 2024 as teams shift from VM management to git-push deploys. the cloud infrastructure market reached $330B in 2024, growing 22% year-over-year (Synergy Research), and PaaS layers capture the majority of new workloads.
When
Use Spring Boot for enterprise Java backends, microservices on JVM, and teams invested in Spring ecosystem. Avoid for lightweight APIs — Node/Python are simpler.
How
1. Build — ./mvnw package or ./gradlew bootJar produces target/app.jar
2. Run — java -jar app.jar, embedded Tomcat on port 8080
3. Docker — eclipse-temurin:21-jre, COPY jar, java -jar
4. Kubernetes — JAR in image, Deployment + Service + HPA
5. Profiles — spring.profiles.active=prod for environment config
6. Actuator — /actuator/health for k8s probes, /actuator/metrics for monitoring
7. GraalVM — native-image for instant startup (no JVM warmup)
Example
# Dockerfile — JRE runtime
FROM eclipse-temurin:21-jre-alpine
WORKDIR /app
COPY target/app.jar app.jar
EXPOSE 8080
HEALTHCHECK --interval=30s CMD wget --spider http://localhost:8080/actuator/health || exit 1
ENTRYPOINT ["java", "-jar", "app.jar", "--spring.profiles.active=prod"]
# Multi-stage build (build + runtime)
FROM maven:3.9-eclipse-temurin-21 AS build
WORKDIR /app
COPY . .
RUN mvn package -DskipTests
FROM eclipse-temurin:21-jre-alpine
COPY --from=build /app/target/app.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
# application-prod.yml
server:
port: 8080
spring:
datasource:
url: ${DATABASE_URL}
management:
endpoints:
web:
exposure:
include: health,metrics
Common Problems
- ⚠JAR is 200MB+ — includes all Spring starters, use spring-boot-gradle-plugin layered jar or jlink
- ⚠JVM cold start 10+ seconds — problem for serverless, use GraalVM native-image for instant start
- ⚠OutOfMemoryError — JVM heap too small, set -Xmx2g or use container-aware JVM (Java 11+)
Best Practices
- ✓Use Java 21+ (container-aware) — auto-detects cgroup memory limits, no manual -Xmx needed
- ✓Enable Spring Boot Actuator health/metrics — gives k8s probes and Prometheus metrics out of the box
- ✓Set up health checks and graceful shutdown — handle SIGTERM to drain in-flight requests before exit