Bird
0
0

Identify the error in this custom properties class that prevents property binding:

medium📝 Debug Q14 of 15
Spring Boot - Application Configuration
Identify the error in this custom properties class that prevents property binding:
@ConfigurationProperties(prefix = "server")
public class ServerProperties {
    private String port;
    public String getPort() { return port; }
    // Missing setter method
}
AMissing setter method for 'port' prevents binding
BPrefix 'server' is invalid and causes error
CClass must be annotated with @Component
DField 'port' should be public for binding
Step-by-Step Solution
Solution:
  1. Step 1: Check property binding requirements

    Spring Boot binds properties using setters. Without a setter for 'port', the value cannot be set.
  2. Step 2: Validate other options

    The prefix 'server' is valid. The class does not require @Component if registered via @EnableConfigurationProperties. Fields should be private with getters/setters, not public.
  3. Final Answer:

    Missing setter method for 'port' prevents binding -> Option A
  4. Quick Check:

    Setter missing = binding fails [OK]
Quick Trick: Always add setters for fields to enable binding [OK]
Common Mistakes:
  • Assuming prefix must be custom or different
  • Thinking @Component is always required
  • Making fields public instead of using setters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes