0
0
Spring Bootframework~20 mins

@ConfigurationProperties for type-safe config in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Spring Boot 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 binding properties with @ConfigurationProperties?
Given the following Spring Boot configuration class and application.properties, what will be the value of appConfig.getTimeout() after the application starts?

AppConfig.java:
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "app")
public class AppConfig {
    private int timeout;
    public int getTimeout() { return timeout; }
    public void setTimeout(int timeout) { this.timeout = timeout; }
}

application.properties:
app.timeout=5000
Spring Boot
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "app")
public class AppConfig {
    private int timeout;
    public int getTimeout() { return timeout; }
    public void setTimeout(int timeout) { this.timeout = timeout; }
}
Anull
B0
CThrows a runtime exception
D5000
Attempts:
2 left
💡 Hint
Check how the prefix in @ConfigurationProperties matches the property keys.
📝 Syntax
intermediate
2:00remaining
Which option correctly defines a nested property class for @ConfigurationProperties?
You want to bind nested properties under prefix 'server' like server.address.host=localhost and server.address.port=8080. Which of the following nested class definitions inside a @ConfigurationProperties class is syntactically correct?
Spring Boot
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "server")
public class ServerConfig {
    private Address address = new Address();
    public Address getAddress() { return address; }
    public void setAddress(Address address) { this.address = address; }

    public static class Address {
        private String host;
        private int port;
        // getters and setters
    }
}
Apublic static class Address { 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; } }
Bpublic class Address { public String host; public int port; }
Cstatic class Address { private String host; private int port; }
Dpublic static class Address { private String host; private int port; }
Attempts:
2 left
💡 Hint
Remember that nested classes for binding need proper getters and setters.
🔧 Debug
advanced
2:00remaining
Why does this @ConfigurationProperties class fail to bind properties?
Consider this class:
@Component
@ConfigurationProperties(prefix = "mail")
public class MailConfig {
    private String host;
    private int port;
}

Given mail.host=smtp.example.com and mail.port=25 in application.properties, why are the properties not bound?
Spring Boot
@Component
@ConfigurationProperties(prefix = "mail")
public class MailConfig {
    private String host;
    private int port;
}
AFields are private but missing getters and setters, so Spring Boot cannot bind them.
BThe prefix 'mail' does not match the property keys.
CThe class is missing @EnableConfigurationProperties annotation.
DThe fields should be static for binding to work.
Attempts:
2 left
💡 Hint
Check how Spring Boot binds properties to fields.
🧠 Conceptual
advanced
2:00remaining
What is the effect of using @ConstructorBinding with @ConfigurationProperties?
When you annotate a class with @ConfigurationProperties and @ConstructorBinding, what changes in how Spring Boot binds properties?
AIt disables binding and requires manual property injection.
BProperties are bound only if setters are present.
CSpring Boot uses the constructor parameters to bind properties instead of setters.
DBinding happens only for static fields.
Attempts:
2 left
💡 Hint
Think about immutable configuration classes.
state_output
expert
2:00remaining
What is the value of 'enabled' after binding with relaxed binding rules?
Given this configuration class:
@Component
@ConfigurationProperties(prefix = "feature")
public class FeatureConfig {
    private boolean enabled;
    public boolean isEnabled() { return enabled; }
    public void setEnabled(boolean enabled) { this.enabled = enabled; }
}

And this property in application.properties:
feature.ENABLED=true

What will be the value of featureConfig.isEnabled() after startup?
Spring Boot
@Component
@ConfigurationProperties(prefix = "feature")
public class FeatureConfig {
    private boolean enabled;
    public boolean isEnabled() { return enabled; }
    public void setEnabled(boolean enabled) { this.enabled = enabled; }
}
Afalse
Btrue
Cnull
DThrows a binding exception
Attempts:
2 left
💡 Hint
Spring Boot property binding is case-insensitive and supports relaxed binding.