Dev vs Prod Configuration in Spring Boot: Key Differences and Usage
dev and prod configurations are managed using profiles that load different application-{profile}.properties or .yml files. The dev profile enables features like debugging and hot reload, while prod focuses on performance, security, and stability settings.Quick Comparison
This table summarizes the main differences between development and production configurations in Spring Boot.
| Aspect | Development (dev) | Production (prod) |
|---|---|---|
| Purpose | Enable debugging and rapid development | Optimize for performance and security |
| Logging Level | DEBUG or TRACE for detailed logs | INFO or WARN to reduce log noise |
| Database | In-memory or test database | Real production database with backups |
| Caching | Usually disabled or minimal | Enabled for performance |
| Security | Relaxed for easier testing | Strict with authentication and authorization |
| Error Handling | Detailed error messages | User-friendly error pages |
Key Differences
Spring Boot uses profiles to separate configuration for different environments. The dev profile is designed to help developers by enabling features like detailed logging, automatic restarts, and using lightweight databases. This makes it easier to spot issues and test changes quickly.
In contrast, the prod profile focuses on stability and security. It disables verbose logging to improve performance and avoid exposing sensitive information. It also connects to real databases and enables caching to handle real user traffic efficiently.
These profiles are activated by setting the spring.profiles.active property, allowing Spring Boot to load the appropriate application-dev.properties or application-prod.properties files automatically.
Code Comparison
Here is an example of a application-dev.properties file for development configuration:
spring.datasource.url=jdbc:h2:mem:testdb spring.datasource.driver-class-name=org.h2.Driver spring.datasource.username=sa spring.datasource.password= spring.jpa.hibernate.ddl-auto=create-drop logging.level.root=DEBUG spring.cache.type=none spring.main.allow-bean-definition-overriding=true
Production Equivalent
And here is the application-prod.properties file for production configuration:
spring.datasource.url=jdbc:postgresql://prod-db-server:5432/proddb spring.datasource.driver-class-name=org.postgresql.Driver spring.datasource.username=produser spring.datasource.password=securepassword spring.jpa.hibernate.ddl-auto=validate logging.level.root=INFO spring.cache.type=simple server.error.whitelabel.enabled=false
When to Use Which
Choose the dev profile when you are actively developing your application and need quick feedback, detailed logs, and easy database resets. It helps you catch bugs early and speeds up your workflow.
Switch to the prod profile when deploying your application to real users. This profile ensures your app runs securely, efficiently, and reliably by using production-grade databases, limiting logs, and enabling caching.