0
0
Spring Bootframework~20 mins

Profile-based configuration in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Profile Configuration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
Spring Boot Profile Activation Behavior
Given a Spring Boot application with application.properties and application-dev.properties files, and the active profile set to dev, what will be the value of the property app.message if application.properties has app.message=Hello from default and application-dev.properties has app.message=Hello from dev?
AHello from default
BAn error occurs because of conflicting properties
CHello from dev
DThe property <code>app.message</code> will be empty
Attempts:
2 left
💡 Hint
Spring Boot uses the active profile properties to override default properties.
📝 Syntax
intermediate
2:00remaining
Correct Syntax for Profile-Specific Bean Declaration
Which of the following is the correct way to declare a Spring bean that only loads when the test profile is active?
A
@Bean
@Profile({test})
public DataSource testDataSource() { return new DataSource(); }
B
@Bean
@Profile(test)
public DataSource testDataSource() { return new DataSource(); }
C
@Bean
@Profile('test')
public DataSource testDataSource() { return new DataSource(); }
D
@Bean
@Profile("test")
public DataSource testDataSource() { return new DataSource(); }
Attempts:
2 left
💡 Hint
Profile annotation requires a string value with double quotes.
🔧 Debug
advanced
2:00remaining
Why Does the Profile-Specific Property Not Load?
A developer has application.properties and application-prod.properties. They set spring.profiles.active=prod in application.properties. But the properties from application-prod.properties are not loaded at runtime. What is the most likely cause?
AThe <code>spring.profiles.active</code> property must be set as a command-line argument or environment variable, not inside <code>application.properties</code>.
BSpring Boot does not support multiple property files for profiles.
CThe profile name <code>prod</code> is misspelled in the filename.
DSetting <code>spring.profiles.active</code> inside <code>application.properties</code> disables profile-specific loading.
Attempts:
2 left
💡 Hint
Active profiles set inside application.properties can cause loading order issues.
state_output
advanced
2:00remaining
Output of Bean Initialization with Multiple Active Profiles
Consider a Spring Boot app with two active profiles: dev and qa. There are two beans defined with @Profile("dev") and @Profile("qa") respectively. What happens when the app starts?
AOnly the bean with <code>@Profile("dev")</code> loads because it is first in the list.
BBoth beans load because both profiles are active.
CNeither bean loads because Spring Boot supports only one active profile at a time.
DAn error occurs due to conflicting beans with different profiles.
Attempts:
2 left
💡 Hint
Spring Boot supports multiple active profiles simultaneously.
🧠 Conceptual
expert
3:00remaining
Understanding Profile-Specific Property Precedence
In Spring Boot, if you have application.properties, application-dev.properties, and application-local.properties, and you activate both dev and local profiles, which property file has the highest precedence when properties conflict?
AThe last profile listed in <code>spring.profiles.active</code> has the highest precedence
B<code>application-dev.properties</code> because it is the first profile alphabetically
C<code>application.properties</code> because it is the base configuration
D<code>application-local.properties</code> because it is loaded last
Attempts:
2 left
💡 Hint
Order of profiles in spring.profiles.active affects property overriding.