Performance: @ConfigurationProperties for type-safe config
This affects application startup time and memory usage by how configuration properties are bound and validated.
@ConfigurationProperties(prefix = "app") public class AppConfig { private int timeout; private String name; // getters and setters }
@Value("${app.timeout}") private int timeout; @Value("${app.name}") private String appName;
| Pattern | Property Lookups | Type Conversions | Startup Time Impact | Verdict |
|---|---|---|---|---|
| Multiple @Value annotations | Multiple (one per property) | Multiple (one per property) | Higher startup time due to repeated work | [X] Bad |
| Single @ConfigurationProperties class | Single batch lookup | Single batch conversion | Lower startup time with efficient binding | [OK] Good |
@ConfigurationProperties in a Spring Boot application?@ConfigurationProperties support in a Spring Boot application?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; }
}@ConfigurationProperties(prefix = "server")
public class ServerConfig {
private String host;
private int port;
public String getHost() { return host; }
public void setHost(String host) { this.host = host; }
public int getPort() { return port; }
public void setPort(int port) { this.port = port; }
}
If the application.yml contains:
server: host: localhost port: notANumberWhat will happen when Spring Boot starts?
app:
security:
enabled: true
roles:
- USER
- ADMIN
Which of the following Java class structures correctly uses @ConfigurationProperties to map this nested config?Pass the test and this pattern moves unknown