Performance: Custom configuration properties
MEDIUM IMPACT
This affects application startup time and memory usage by how configuration properties are loaded and bound.
Using a single @ConfigurationProperties class to bind all related properties: @ConfigurationProperties(prefix = "app") public class AppProperties { private int timeout; private String url; // getters and setters } @Configuration @EnableConfigurationProperties(AppProperties.class) public class MyService { private final AppProperties props; public MyService(AppProperties props) { this.props = props; } }
Using @Value annotations repeatedly for many properties scattered across classes: @Component public class MyService { @Value("${app.timeout}") private int timeout; @Value("${app.url}") private String url; // many more @Value injections }
| Pattern | Property Lookups | Startup Delay | Memory Usage | Verdict |
|---|---|---|---|---|
| Multiple @Value annotations | Many repeated lookups | Higher (tens of ms) | Higher due to scattered bindings | [X] Bad |
| Single @ConfigurationProperties class | Single batch lookup | Lower (few ms) | Lower due to structured binding | [OK] Good |