0
0
Spring Bootframework~20 mins

@Profile for environment-specific beans in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Profile Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What bean is loaded with active profile 'dev'?
Given these two Spring beans with @Profile annotations, which bean will be loaded when the active profile is set to 'dev'?
Spring Boot
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Component
@Profile("dev")
public class DevService {
    public String getName() { return "Development Service"; }
}

@Component
@Profile("prod")
public class ProdService {
    public String getName() { return "Production Service"; }
}
ABoth DevService and ProdService beans are loaded.
BProdService bean is loaded and DevService is ignored.
CDevService bean is loaded and ProdService is ignored.
DNo beans are loaded because profiles conflict.
Attempts:
2 left
💡 Hint
Think about how @Profile controls bean loading based on active profiles.
📝 Syntax
intermediate
2:00remaining
Which @Profile annotation syntax is correct?
Which option shows the correct way to use @Profile to specify multiple profiles for a bean in Spring Boot?
A@Profile(dev | test)
B@Profile({"dev", "test"})
C@Profile(dev, test)
D@Profile("dev, test")
Attempts:
2 left
💡 Hint
Check how arrays are passed in Java annotations.
🔧 Debug
advanced
2:00remaining
Why does this bean not load despite active profile?
Given this bean definition and active profile 'prod', why does Spring fail to load the bean?
Spring Boot
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Component
@Profile("production")
public class PaymentService {
    // service code
}
ABecause the active profile is 'prod' but the bean is annotated with 'production'.
BBecause @Component is missing.
CBecause the class is not public.
DBecause @Profile cannot be used on classes.
Attempts:
2 left
💡 Hint
Check if the profile names match exactly.
state_output
advanced
2:00remaining
What is the output when no active profile is set?
Consider these two beans with @Profile annotations. What happens if no active profile is set in the Spring Boot application?
Spring Boot
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Component
@Profile("dev")
public class DevConfig {
    public String getConfig() { return "Dev Config"; }
}

@Component
@Profile("prod")
public class ProdConfig {
    public String getConfig() { return "Prod Config"; }
}
AOnly ProdConfig bean is loaded by default.
BBoth DevConfig and ProdConfig beans are loaded.
COnly DevConfig bean is loaded by default.
DNeither DevConfig nor ProdConfig beans are loaded.
Attempts:
2 left
💡 Hint
Think about what happens when no profile is active and beans require profiles.
🧠 Conceptual
expert
2:00remaining
How to load a bean for all profiles except 'test'?
Which @Profile expression correctly loads a bean for all profiles except 'test' in Spring Boot?
A@Profile("!test")
B@Profile("all & !test")
C@Profile("!test") and @Profile("*")
D@Profile("!test") and @Profile("default")
Attempts:
2 left
💡 Hint
Spring supports negation in @Profile expressions.