Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to enable binding of properties to the class.
Spring Boot
@[1]("app.settings") public class AppSettings { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Component instead of @ConfigurationProperties
Forgetting to specify the prefix in the annotation
✗ Incorrect
The @ConfigurationProperties annotation binds external properties to this class using the specified prefix.
2fill in blank
mediumComplete the code to register the configuration properties class as a Spring bean.
Spring Boot
@Bean public [1] appSettings() { return new AppSettings(); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the annotation name instead of the class
Returning a Spring stereotype annotation instead of the class
✗ Incorrect
The method returns an instance of the AppSettings class to register it as a bean.
3fill in blank
hardFix the error in the class to properly bind nested properties.
Spring Boot
public class DatabaseProperties { private String url; private Credentials [1]; public static class Credentials { private String username; private String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public Credentials getCredentials() { return credentials; } public void setCredentials(Credentials credentials) { this.credentials = credentials; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase for the field name
Using a different name than the getter/setter methods
✗ Incorrect
The field name must match the getter/setter and property name to bind nested properties correctly.
4fill in blank
hardFill both blanks to complete the annotation and enable validation.
Spring Boot
@[1]("server.config") @[2] public class ServerConfig { @NotNull private Integer port; public Integer getPort() { return port; } public void setPort(Integer port) { this.port = port; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting @Validated annotation
Using @Component instead of @ConfigurationProperties
✗ Incorrect
Use @ConfigurationProperties to bind properties and @Validated to enable validation annotations like @NotNull.
5fill in blank
hardFill all three blanks to create a type-safe configuration with nested properties and validation.
Spring Boot
@[1]("mail.settings") @[2] public class MailSettings { private Smtp smtp; public static class Smtp { @NotEmpty private String host; @Min([3]) 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; } } public Smtp getSmtp() { return smtp; } public void setSmtp(Smtp smtp) { this.smtp = smtp; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting @Validated annotation
Setting @Min to 0 or negative values
Using @Component instead of @ConfigurationProperties
✗ Incorrect
Use @ConfigurationProperties to bind, @Validated to enable validation, and @Min(1) to ensure port is at least 1.