Bird
0
0

Which of these is a valid way to activate a Spring profile named 'dev' when running the application?

easy📝 Conceptual Q2 of 15
Spring Boot - Spring Annotations
Which of these is a valid way to activate a Spring profile named 'dev' when running the application?
AAdd @EnableProfile("dev") annotation to the main class
BSet the JVM argument: -Dspring.profiles.active=dev
CUse @Profile("dev") on the main application class
DSet environment variable SPRING_PROFILE=dev
Step-by-Step Solution
Solution:
  1. Step 1: Identify how to activate profiles

    Spring Boot activates profiles via the property spring.profiles.active, which can be set as a JVM argument.
  2. Step 2: Evaluate other options

    @EnableProfile does not exist, @Profile is for beans, and SPRING_PROFILE is not the correct env variable name.
  3. Final Answer:

    Set the JVM argument: -Dspring.profiles.active=dev -> Option B
  4. Quick Check:

    Activate profile = -Dspring.profiles.active=dev [OK]
Quick Trick: Use -Dspring.profiles.active=profileName to activate profiles [OK]
Common Mistakes:
  • Using @EnableProfile which is invalid
  • Confusing @Profile usage with activation
  • Setting wrong environment variable name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes