Member-only story
Deploy Spring Boot Applications with Profile-Based Settings | Step-by-Step Guide
Learn how to deploy Spring Boot applications with different profiles (dev, test, prod). Configure environments using application.properties
, @Profile
, and cloud-based deployment settings.
🚀 Introduction: Why Use Profile-Based Settings in Deployment?
Spring Boot Profiles allow developers to configure different settings for different environments (Development, Testing, Production) and switch between them dynamically.
✅ Why Use Profiles for Deployment?
✔ Environment-Specific Configurations — Different databases, API keys, logging levels.
✔ Easier Deployment Management — No need to modify code for different environments.
✔ Better Security — Avoid exposing production credentials in the development environment.
✔ Supports Cloud & Docker Deployments — Works with AWS, Azure, Kubernetes.
📌 In this guide, you’ll learn:
✅ How to configure Spring Boot profiles (dev
, test
, prod
).
✅ How to activate profiles during deployment.
✅ How to deploy Spring Boot with profile-based settings.
1️⃣ Configure Spring Boot Profiles for Deployment
By default, Spring Boot loads application.properties
, but we can define environment-specific files like:
application-dev.properties
application-test.properties
application-prod.properties
📌 Example: application-dev.properties
(Local Development Settings)
server.port=8081
spring.datasource.url=jdbc:h2:mem:devdb
spring.datasource.username=sa
spring.datasource.password=
logging.level.root=DEBUG
📌 Example: application-prod.properties
(Production Settings)
server.port=8080
spring.datasource.url=jdbc:mysql://prod-db-server:3306/proddb
spring.datasource.username=produser
spring.datasource.password=securepassword
logging.level.root=ERROR
🚀 Spring Boot will automatically pick the right file based on the active profile!