Spring Boot FAQ: Top Questions
45. How do you use profiles to manage environment-specific configurations?
Spring Boot allows you to define separate property files for different environments using the spring.profiles.active setting.
πΊοΈ Steps:
- Create
application-dev.properties,application-prod.properties, etc. - Activate a profile via CLI, environment variable, or
application.properties.
π₯ Example:
spring.profiles.active=dev
π Expected Output:
Loads application-dev.properties at runtime.
π οΈ Use Cases:
- Managing config across dev, test, and prod environments.
- Avoiding hardcoded values and sensitive info in codebase.
