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 packageProduces:
target/app.jarContains 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"]