Complete the code to load a property value from application.properties.
@Value("$[1]") private String appName;
The @Value annotation loads the property named app.name from the configuration file.
Complete the code to define a configuration property with a default value.
@Value("${custom.timeout:[1]") private int timeout;
The default value 30 is used if custom.timeout is not set in the configuration.
Fix the error in the configuration property injection.
@Value("$[1]") private String databaseUrl;
The correct property key uses dots to separate words, like spring.datasource.url.
Fill both blanks to create a configuration class with a property prefix.
@ConfigurationProperties(prefix = "[1]") public class [2]Config { private String url; public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } }
The prefix database matches the property group, and the class name DatabaseConfig follows Java naming conventions.
Fill all three blanks to bind nested configuration properties.
@ConfigurationProperties(prefix = "[1]") public class [2]Config { private final [3] security = new [3](); public [3] getSecurity() { return security; } public static class Security { private boolean enabled; public boolean isEnabled() { return enabled; } public void setEnabled(boolean enabled) { this.enabled = enabled; } } }
The prefix server groups related properties, the class ServerConfig matches the prefix, and the nested class Security holds security settings.