Bird
0
0

Which of these is a correct way to inject the property app.title into a String field using @Value?

easy📝 Conceptual Q2 of 15
Spring Boot - Spring Annotations
Which of these is a correct way to inject the property app.title into a String field using @Value?
A@Value('${app.title}') private String title;
B@Value(app.title) private String title;
C@Value("app.title") private String title;
D@Value("${app.title}") private String title;
Step-by-Step Solution
Solution:
  1. Step 1: Check correct syntax for property injection

    The correct syntax uses ${property.name} inside quotes to reference the property value.
  2. Step 2: Identify correct option

    @Value("${app.title}") private String title; uses @Value("${app.title}") which is the correct way. @Value('${app.title}') private String title; uses single quotes inside double quotes which is invalid in Java annotations.
  3. Final Answer:

    @Value("${app.title}") private String title; -> Option D
  4. Quick Check:

    Property injection syntax = ${property.name} [OK]
Quick Trick: Always use ${property.name} inside double quotes [OK]
Common Mistakes:
  • Omitting ${} around property name
  • Using single quotes inside annotation incorrectly
  • Not quoting the property expression

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes