0
0
Spring Bootframework~20 mins

Custom configuration properties in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Custom Config Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output when accessing a custom property in Spring Boot?
Given a Spring Boot application with a custom configuration property app.title=MyApp defined in application.properties and a @ConfigurationProperties class binding it, what will be the output of System.out.println(appProperties.getTitle())?
Spring Boot
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "app")
public class AppProperties {
    private String title;
    public String getTitle() { return title; }
    public void setTitle(String title) { this.title = title; }
}

// application.properties
// app.title=MyApp

// In some service or main method:
// System.out.println(appProperties.getTitle());
Aapp.title
Bnull
CMyApp
DCompilation error due to missing @EnableConfigurationProperties
Attempts:
2 left
💡 Hint
Remember that Spring Boot automatically binds properties with matching prefix to the fields in the class annotated with @ConfigurationProperties.
📝 Syntax
intermediate
2:00remaining
Which code snippet correctly enables custom configuration properties in Spring Boot?
You want to enable a class DatabaseSettings annotated with @ConfigurationProperties(prefix = "db") to be loaded as a bean. Which of the following code snippets correctly enables this?
A
@SpringBootApplication
@EnableAutoConfiguration
public class App {}
B
@SpringBootApplication
@ComponentScan(basePackages = "db")
public class App {}
C
@SpringBootApplication
@ConfigurationPropertiesScan
public class App {}
D
@SpringBootApplication
@EnableConfigurationProperties(DatabaseSettings.class)
public class App {}
Attempts:
2 left
💡 Hint
Use the annotation that explicitly enables configuration properties classes.
🔧 Debug
advanced
2:30remaining
Why does the custom configuration property not bind correctly?
Given the class below, why does the property server.port=8081 not bind to the port field?
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "server")
public class ServerConfig {
    private int port;
    public int getPort() { return port; }
    // Missing setter method
}
AMissing setter method for 'port' prevents Spring from setting the value.
BThe prefix 'server' is incorrect; it should be 'server.port'.
CThe class must be annotated with @Configuration instead of @Component.
DThe field 'port' must be public for binding to work.
Attempts:
2 left
💡 Hint
Spring Boot uses setters to inject property values.
state_output
advanced
2:00remaining
What is the value of the list property after binding?
Given the following properties and class, what will be the value of appProperties.getServers()?
application.yml:
app:
  servers:
    - host1.example.com
    - host2.example.com

Java class:
@Component
@ConfigurationProperties(prefix = "app")
public class AppProperties {
    private List servers;
    public List getServers() { return servers; }
    public void setServers(List servers) { this.servers = servers; }
}
ACompilation error due to missing @EnableConfigurationProperties
B["host1.example.com", "host2.example.com"]
C["app.servers"]
Dnull
Attempts:
2 left
💡 Hint
YAML lists map to Java List fields with matching names.
🧠 Conceptual
expert
3:00remaining
Which statement about @ConfigurationProperties and validation is correct?
Consider a class annotated with @ConfigurationProperties(prefix = "mail") and fields annotated with @NotNull from javax.validation.constraints. Which statement is true about validation of these properties?
AValidation annotations are ignored unless @Validated is added to the class.
BValidation happens automatically without any extra annotation.
CValidation requires implementing Validator interface manually.
DValidation only works if properties are loaded from YAML, not properties files.
Attempts:
2 left
💡 Hint
Spring Boot requires an extra annotation to trigger validation on configuration properties.