π± What are Spring Profiles?
Spring Profiles allow you to define different configurations for different environments β like dev, test, or prod.
π Instead of changing code every time you deploy, you create separate config files, and Spring Boot automatically picks the right one.
π‘ Real-Life Example
You might want:
- Local DB for development
- MySQL for production
- H2 for testing
Using profiles, you can define different properties for each case.
π How to Create Profiles
1. Create property files:
application-dev.properties Β
application-test.properties Β
application-prod.properties
2. In each file, define environment-specific values:
Example application-dev.properties
:
server.port=8081
spring.datasource.url=jdbc:h2:mem:testdb
Example application-prod.properties
: