Bird
0
0

Given the following YAML:

medium📝 component behavior Q5 of 15
Spring Boot - Application Configuration
Given the following YAML:
database:
  url: jdbc:mysql://localhost:3306/mydb
  maxConnections: 20

And this class:
@ConfigurationProperties(prefix = "database")
public class DatabaseConfig {
  private String url;
  private int maxConnections;

  // getters and setters
}

What will be the value of databaseConfig.getMaxConnections() after binding?
AThrows an exception due to missing annotation
B0
Cnull
D20
Step-by-Step Solution
Solution:
  1. Step 1: Identify prefix and properties

    The prefix is "database" and properties url and maxConnections match the YAML keys.
  2. Step 2: Binding process

    Spring Boot binds maxConnections to 20 as per YAML.
  3. Final Answer:

    20 -> Option D
  4. Quick Check:

    Property names and types match YAML values [OK]
Quick Trick: Property names must match YAML keys for binding [OK]
Common Mistakes:
  • Assuming default values override YAML
  • Forgetting to add getters/setters
  • Confusing null with zero for primitives

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes