Bird
0
0

Which of the following is the correct way to use @Profile on a Spring bean class for the "dev" environment?

easy📝 Syntax Q12 of 15
Spring Boot - Spring Annotations
Which of the following is the correct way to use @Profile on a Spring bean class for the "dev" environment?
A@Profile("dev") public class DevService {}
B@Profile(dev) public class DevService {}
C@Profile({dev}) public class DevService {}
D@Profile(["dev"]) public class DevService {}
Step-by-Step Solution
Solution:
  1. Step 1: Check correct syntax for @Profile

    The @Profile annotation requires a string value in quotes, e.g., @Profile("dev").
  2. Step 2: Analyze each option

    @Profile(["dev"]) public class DevService {} uses square brackets, invalid Java annotation syntax. @Profile(dev) public class DevService {} misses quotes around "dev", syntax error. @Profile({dev}) public class DevService {} uses braces but misses quotes around "dev", syntax error. @Profile("dev") public class DevService {} uses correct quoted string syntax.
  3. Final Answer:

    @Profile("dev") public class DevService {} -> Option A
  4. Quick Check:

    @Profile needs quoted string [OK]
Quick Trick: Use quotes around profile names in @Profile [OK]
Common Mistakes:
  • Omitting quotes around profile names
  • Using square brackets instead of curly braces
  • Confusing array syntax with string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes