Bird
0
0

How can you ensure the staging profile is used only in deployment without changing code?

hard📝 Conceptual Q8 of 15
Spring Boot - Docker and Deployment

You want to create a Spring Boot application that uses a default profile but switches to staging profile when deployed. How can you ensure the staging profile is used only in deployment without changing code?

AHardcode <code>staging</code> profile in the main application class
BUse a command line argument to activate <code>staging</code> profile during development
CRename <code>application.properties</code> to <code>application-staging.properties</code>
DSet <code>spring.profiles.active=staging</code> as an environment variable on the deployment server
Step-by-Step Solution
Solution:
  1. Step 1: Understand profile activation without code changes

    Profiles can be activated via environment variables or command line arguments.
  2. Step 2: Choose environment variable for deployment

    Setting 'spring.profiles.active=staging' as an environment variable on the server activates the profile without code changes.
  3. Final Answer:

    Set spring.profiles.active=staging as an environment variable on the deployment server -> Option D
  4. Quick Check:

    Use env vars to switch profiles without code [OK]
Quick Trick: Use environment variables to activate profiles in deployment [OK]
Common Mistakes:
  • Hardcoding profiles in code
  • Renaming default properties file incorrectly
  • Activating staging profile during development

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes