Bird
0
0

You want to bind a list of strings from application.yml like:

hard📝 Application Q8 of 15
Spring Boot - Application Configuration
You want to bind a list of strings from application.yml like:
app:
  servers:
    - host1
    - host2
    - host3

Which of the following is the correct way to declare the property in a @ConfigurationProperties class?
Aprivate List<String> servers;
Bprivate String[] server;
Cprivate Map<String, String> servers;
Dprivate String servers;
Step-by-Step Solution
Solution:
  1. Step 1: Identify the YAML structure

    The YAML defines a list of strings under app.servers.
  2. Step 2: Choose the matching Java type

    A List<String> matches the list structure perfectly and is the recommended type for flexibility.
  3. Step 3: Select the best option

    private List servers; uses List, which is idiomatic and works well with Spring Boot binding.
  4. Final Answer:

    private List<String> servers; -> Option A
  5. Quick Check:

    List binding = A [OK]
Quick Trick: Use List for YAML lists in properties [OK]
Common Mistakes:
  • Using Map instead of List for a list property
  • Using String instead of a collection type
  • Assuming arrays are always better than lists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes