Spring Boot Production Deployment & Optimization

boot.cloud
Boot to Cloud
Published on May, 11 2026 2 min read 0 comments
image

In Week 7, we mastered testing: unit tests, integration tests, and performance monitoring.
Now, in Week 8, it’s time to prepare your Spring Boot application for production.

We’ll cover:

  • Profiles & environment configurations
  • Packaging & Dockerization
  • Deployment strategies (Cloud / On-Prem)
  • Performance optimization
  • Monitoring & logging

By the end, your Spring Boot project will be production-ready, scalable, and maintainable.

Step 1: Use Spring Profiles

Spring Boot allows environment-specific configurations using profiles: dev, test, prod.

Folder structure:

src/main/resources/
 β”œβ”€β”€ application.yml
 β”œβ”€β”€ application-dev.yml
 β”œβ”€β”€ application-prod.yml

Example application-prod.yml:

server:
  port: 8080

spring:
  datasource:
    url: jdbc:mysql://prod-db:3306/prod_db
    username: prod_user
    password: ${DB_PASSWORD}
  jpa:
    hibernate:
      ddl-auto: validate
    show-sql: false

Activate profile at runtime:

java -jar app.jar --spring.profiles.active=prod

βœ… Benefits:

  • Clean separation between environments
  • No accidental dev configs in production

Step 2: Packaging Your Application

Create Executable Jar

mvn clean package
  • Produces: target/app.jar
  • Contains embedded Tomcat server β†’ easy to run

Run the Jar

java -jar target/app.jar

Optional: run in background with systemd or nohup:

nohup java -jar target/app.jar > app.log 2>&1 &

Step 3: Dockerize Spring Boot

Dockerfile Example

# Use OpenJDK 17 base image
FROM openjdk:17-jdk-alpine

# Set workdir
WORKDIR /app

# Copy jar
COPY target/app.jar app.jar

# Expose port
EXPOSE 8080

# Run the app
ENTRYPOINT ["java","-jar","app.jar"]

Build Docker Image

docker build -t springboot-app:1.0 .

Run Docker Container

docker run -d -p 8080:8080 --name springboot-app springboot-app:1.0

βœ… Benefits:

  • Containerized apps are portable
  • Easy to deploy on Kubernetes or cloud

Step 4: Cloud Deployment Options

AWS

  • EC2: Deploy Jar or Docker container
  • ECS / EKS: Dockerized deployment with scaling
  • RDS: Managed MySQL/Postgres

Azure

  • App Service: Simple Spring Boot deployment
  • AKS: Kubernetes deployment

GCP

  • Compute Engine: VM-based deployment
  • GKE: Kubernetes cluster deployment

Step 5: Performance Optimization

  • Enable connection pooling (HikariCP default)
spring:
  datasource:
    hikari:
      maximum-pool-size: 20
  • Disable SQL logging in production
  • Enable caching
@EnableCaching
  • Optimize JPA queries
    • Avoid N+1 problem
    • Use JOIN FETCH for relations
  • Use asynchronous processing
@Async
public void sendEmail() { ... }

 

Step 6: Monitoring & Metrics

Spring Boot Actuator

management:
  endpoints:
    web:
      exposure:
        include: health, metrics, httptrace
  • Access /actuator/health β†’ System health
  • Access /actuator/metrics β†’ Response times, DB queries, JVM memory

Optional Tools

  • Prometheus + Grafana β†’ Visualize metrics
  • ELK Stack β†’ Centralized logging
  • Sentry β†’ Exception monitoring

Step 7: Security & Best Practices

  • Never store passwords in config β†’ use environment variables
  • Enable HTTPS using reverse proxy (Nginx)
  • Limit request size & enable rate limiting
  • Keep dependencies updated
  • Use JWT tokens and secure headers for APIs

Week 8 Recap

βœ… Profiles for dev/test/prod
βœ… Packaging Spring Boot apps as Jar
βœ… Dockerization for portability
βœ… Cloud deployment options
βœ… Performance tuning (caching, DB optimization)
βœ… Monitoring & logging

Series Conclusion

Congratulations! πŸŽ‰ You’ve completed the 8-week Spring Boot series.

You now know how to:

  • Set up a professional Spring Boot project
  • Build REST APIs
  • Connect to databases with JPA/Hibernate
  • Secure APIs with JWT
  • Handle errors and log effectively
  • Test thoroughly (unit, integration, performance)
  • Deploy and optimize for production

This foundation allows you to scale, maintain, and extend your applications professionally.

πŸ“Œ Action Items

βœ” Configure production profile
βœ” Package and Dockerize your app
βœ” Deploy to cloud / local server
βœ” Monitor logs and metrics
βœ” Optimize JPA queries and caching

0 Comments