Bird
0
0

You want to create a bean that is active in both "dev" and "test" profiles but not in "prod". Which @Profile annotation usage correctly achieves this?

hard📝 Application Q15 of 15
Spring Boot - Spring Annotations
You want to create a bean that is active in both "dev" and "test" profiles but not in "prod". Which @Profile annotation usage correctly achieves this?
A@Profile({"dev", "test"})
B@Profile("dev & test")
C@Profile("dev | test")
D@Profile({"dev & test"})
Step-by-Step Solution
Solution:
  1. Step 1: Understand @Profile multiple values usage

    Using @Profile({"dev", "test"}) means the bean is active if either "dev" OR "test" profile is active.
  2. Step 2: Analyze other options

    @Profile("dev & test") and D use string with "&" which is invalid syntax for multiple profiles. @Profile("dev | test") uses "|" inside string which is not supported syntax.
  3. Final Answer:

    @Profile({"dev", "test"}) -> Option A
  4. Quick Check:

    Use array of profiles for OR condition in @Profile [OK]
Quick Trick: Use array syntax for multiple profiles in @Profile [OK]
Common Mistakes:
  • Using string with & or | inside @Profile
  • Confusing AND and OR logic in profiles
  • Forgetting to use curly braces for multiple profiles

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes