Challenge - 5 Problems
Spring Boot Profiles Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the active profile output?
Given a Spring Boot application with two profiles dev and prod, and the following configuration:
What will
application.properties:
spring.profiles.active=dev
application-dev.properties:
app.message=Development Mode
application-prod.properties:
app.message=Production Mode
@Component
public class MessagePrinter {
@Value("${app.message}")
private String message;
public String getMessage() {
return message;
}
}What will
getMessage() return when the application runs?Attempts:
2 left
💡 Hint
Check which profile is active in
application.properties.✗ Incorrect
The active profile is set to 'dev', so Spring loads
application-dev.properties. The app.message value is 'Development Mode'.📝 Syntax
intermediate2:00remaining
Which configuration activates the 'test' profile correctly?
You want to activate the 'test' profile in a Spring Boot application. Which of the following ways correctly activates the profile?
Attempts:
2 left
💡 Hint
Activating a profile means telling Spring which profile to use when starting.
✗ Incorrect
Setting the environment variable SPRING_PROFILES_ACTIVE=test activates the 'test' profile globally. Adding the property inside
application-test.properties does not activate it by itself.🔧 Debug
advanced2:00remaining
Why does the bean not load for 'prod' profile?
Consider this Spring Boot bean:
When running with the 'dev' profile active, the application fails to find
@Component
@Profile("prod")
public class ProdService {
// service code
}When running with the 'dev' profile active, the application fails to find
ProdService and throws a NoSuchBeanDefinitionException. Why?Attempts:
2 left
💡 Hint
Check which profile is active and how @Profile works.
✗ Incorrect
The @Profile("prod") annotation means the bean is only created when the 'prod' profile is active. With 'dev' active, Spring skips this bean.
❓ state_output
advanced2:00remaining
What is the value of 'timeout' after loading profiles?
Given these property files:
application.properties: timeout=30 application-dev.properties: timeout=10 application-prod.properties: timeout=60 And the active profile is set to 'prod'. What is the value oftimeoutinjected by@Value("${timeout}")?
Attempts:
2 left
💡 Hint
Profile-specific properties override default properties.
✗ Incorrect
The 'prod' profile is active, so
application-prod.properties overrides timeout to 60.🧠 Conceptual
expert3:00remaining
How does Spring Boot resolve multiple active profiles with conflicting properties?
If you set multiple active profiles like
spring.profiles.active=dev,prod and both profiles define the same property app.mode with different values, which value does Spring Boot use?Attempts:
2 left
💡 Hint
Think about the order Spring Boot loads profile properties.
✗ Incorrect
Spring Boot loads profiles in order and later profiles override earlier ones. So the last profile's property wins.