0
0
SpringbootComparisonBeginner · 4 min read

Dev vs Prod Configuration in Spring Boot: Key Differences and Usage

In Spring Boot, 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.

AspectDevelopment (dev)Production (prod)
PurposeEnable debugging and rapid developmentOptimize for performance and security
Logging LevelDEBUG or TRACE for detailed logsINFO or WARN to reduce log noise
DatabaseIn-memory or test databaseReal production database with backups
CachingUsually disabled or minimalEnabled for performance
SecurityRelaxed for easier testingStrict with authentication and authorization
Error HandlingDetailed error messagesUser-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:

properties
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:

properties
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.

Key Takeaways

Use Spring Boot profiles to separate dev and prod configurations cleanly.
Dev profile enables debugging, in-memory databases, and verbose logging.
Prod profile focuses on security, performance, and stable database connections.
Activate profiles via spring.profiles.active property for environment-specific settings.
Switch profiles based on your current phase: development or production deployment.