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.ymlExample 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: falseActivate 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.jarOptional: 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+1problem - Use
JOIN FETCHfor relations
- Avoid
- 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