Spring Boot Externalized Configuration and Profiles 4 — Questions and Answers
Question 1: Which directory location takes the highest precedence for application.properties in a default Spring Boot setup?
- /config subdirectory of the current directory (Correct answer)
- classpath:/
- classpath:/config/
- Current working directory
Correct answer: /config subdirectory of the current directory
The ./config/ subdirectory has the highest file-system precedence in Spring Boot's default config file search order.
Question 2: What is the correct way to inject a property named 'app.max-retries' into a Spring bean field?
- @Value("app.max-retries")
- @Value("${app.max-retries}") (Correct answer)
- @Value("#{app.max-retries}")
- @Inject("app.max-retries")
Correct answer: @Value("${app.max-retries}")
@Value uses ${...} syntax for property placeholders to resolve values from the Environment.
Question 3: What does the @EnableConfigurationProperties annotation do?
- Enables YAML support in Spring Boot
- Registers specified @ConfigurationProperties classes as beans (Correct answer)
- Activates externalized configuration globally
- Enables environment variable binding
Correct answer: Registers specified @ConfigurationProperties classes as beans
@EnableConfigurationProperties registers the specified @ConfigurationProperties-annotated classes as Spring beans.
Question 4: Which Spring Boot test slice annotation loads only configuration-related beans for faster tests?
- @SpringBootTest
- @ConfigurationPropertiesTest (Correct answer)
- @WebMvcTest
- @DataJpaTest
Correct answer: @ConfigurationPropertiesTest
@ConfigurationPropertiesTest loads only ConfigurationProperties beans, making it lightweight for testing property binding.
Question 5: How can you provide default values for a property injected via @Value?
- @Value("${prop:defaultValue}") (Correct answer)
- @Value("${prop||defaultValue}")
- @Value("${prop?defaultValue}")
- @DefaultValue("prop")
Correct answer: @Value("${prop:defaultValue}")
The colon syntax ${property:default} provides a fallback when the property is not defined.
Question 6: What type does Spring Boot use to represent a list of values in application.properties?
- Only JSON arrays are supported
- Comma-separated strings that bind to List<T> or arrays (Correct answer)
- Only YAML sequences are supported
- Semi-colon-separated strings
Correct answer: Comma-separated strings that bind to List<T> or arrays
Spring Boot's relaxed binding converts comma-separated property values to List or array types when bound with @ConfigurationProperties.
Question 7: Which Spring Boot actuator endpoint exposes the resolved configuration properties?
- /actuator/env (Correct answer)
- /actuator/properties
- /actuator/config
- /actuator/settings
Correct answer: /actuator/env
The /actuator/env endpoint shows all property sources and their resolved values, useful for debugging configuration.
Which directory location takes the highest precedence for application.properties in a default Spring Boot setup?