Bird
0
0

A developer wrote this class:

medium📝 Debug Q7 of 15
Spring Boot - Application Configuration
A developer wrote this class:
@ConfigurationProperties(prefix = "db")
public class DatabaseConfig {
  private String url;
  private String username;
  private String password;

  // no getters or setters
}

Why will the properties not bind correctly?
AMissing getters and setters prevent binding
BPrefix "db" is invalid
CClass must be abstract
DFields must be public
Step-by-Step Solution
Solution:
  1. Step 1: Understand binding requirements

    @ConfigurationProperties requires standard JavaBean getters and setters for binding to work.
  2. Step 2: Evaluate other options

    Prefix "db" is valid, class should not be abstract, and fields do not need to be public if getters/setters exist.
  3. Final Answer:

    Missing getters and setters prevent binding -> Option A
  4. Quick Check:

    Getters/setters needed for binding [OK]
Quick Trick: Always add getters and setters for binding [OK]
Common Mistakes:
  • Assuming public fields bind automatically
  • Thinking prefix must be special
  • Making class abstract unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes