Bird
0
0

Given the following properties:

medium📝 component behavior Q4 of 15
Spring Boot - Application Configuration
Given the following properties:
app.name=MyApp
app.version=1.0
and this class:
@ConfigurationProperties(prefix = "app")
public class AppConfig {
  private String name;
  private String version;

  // getters and setters
}

What will be the value of appConfig.getVersion() after binding?
Anull
B1.0
CMyApp
Dapp.version
Step-by-Step Solution
Solution:
  1. Step 1: Match property keys with class fields

    Properties with prefix 'app' map to fields 'name' and 'version' in AppConfig class.
  2. Step 2: Identify value for version field

    app.version=1.0 maps to version field, so getVersion() returns "1.0".
  3. Final Answer:

    1.0 -> Option B
  4. Quick Check:

    Property binding value = 1.0 [OK]
Quick Trick: Property keys map to fields by prefix and name [OK]
Common Mistakes:
  • Mixing values of different fields
  • Expecting raw property key as value
  • Forgetting to add getters/setters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes