Bird
0
0

Given the following configuration class and properties, what will be the value of appProperties.getTimeout()?

medium📝 component behavior Q13 of 15
Spring Boot - Application Configuration
Given the following configuration class and properties, what will be the value of appProperties.getTimeout()?
application.yml:
app:
  timeout: 5000

Java class:
@ConfigurationProperties(prefix = "app")
public class AppProperties {
    private int timeout;
    public int getTimeout() { return timeout; }
    public void setTimeout(int timeout) { this.timeout = timeout; }
}
A5000
B0
Cnull
DThrows an exception
Step-by-Step Solution
Solution:
  1. Step 1: Match property prefix and field

    The prefix 'app' matches the class prefix, and 'timeout' matches the field name, so the value 5000 binds correctly.
  2. Step 2: Understand default value and binding

    Since the property is set in the YAML, the field will be set to 5000, not the default 0 or null.
  3. Final Answer:

    5000 -> Option A
  4. Quick Check:

    Property value binds correctly = 5000 [OK]
Quick Trick: Match prefix and field names exactly for binding [OK]
Common Mistakes:
  • Assuming default 0 because of missing @Value
  • Confusing null with primitive int default
  • Expecting exception without validation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes