Loading...
27

I need to configure different database settings for dev, test, and production environments in my Spring Boot application.

What's the best way to use profiles? Should I use separate YAML files or profiles within one file?

Also, how do I set the active profile when running the application?

asked 6 days ago
micro_king 1.2k

Log in to add a comment.

1 Answer

22

Spring Boot profiles are perfect for environment-specific configurations. Here's the recommended approach:

Option 1: Separate files (Recommended)
__CODEBLOCK0

*application.yml:
_CODE_BLOCK_1_

Activating profiles:

  1. </em><em>application.properties:</em><em>
_CODE_BLOCK_2_
  1. </em><em>Command line:</em><em>
_CODE_BLOCK_3_
  1. </em><em>Environment variable:</em><em>
_CODE_BLOCK_4_
  1. </em><em>In code (for testing):</em>*
CODEBLOCK5__

Best Practice: Use environment variables for sensitive data in production, never commit secrets to git!

answered 5 days ago
Log in to answer this question.
Question Stats
Asked: 6 days ago
Views: 781
Active: 1 day ago
Related Tags