0
0
Spring Bootframework~5 mins

Conditional bean creation in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is @Conditional annotation used for in Spring Boot?
It is used to create beans only when certain conditions are met, like checking if a class exists or a property is set.
Click to reveal answer
beginner
Name two common built-in conditions for conditional bean creation in Spring Boot.
@ConditionalOnProperty and @ConditionalOnClass are commonly used to create beans based on property values or presence of classes.
Click to reveal answer
intermediate
How does @ConditionalOnProperty control bean creation?
It creates a bean only if a specific property is present and optionally matches a value in the application configuration.
Click to reveal answer
beginner
What happens if a condition in @Conditional is not met?
The bean is not created or registered in the Spring context, so it won't be available for injection.
Click to reveal answer
intermediate
Explain how @ConditionalOnMissingBean helps in bean creation.
It creates a bean only if no other bean of the same type or name is already defined, helping avoid duplicates.
Click to reveal answer
Which annotation creates a bean only if a certain property is set in Spring Boot?
A@Autowired
B@ConditionalOnClass
C@ConditionalOnMissingBean
D@ConditionalOnProperty
What does @ConditionalOnClass check before creating a bean?
AIf a property is set
BIf a class is present on the classpath
CIf a bean is missing
DIf a method is called
If a condition in @Conditional is false, what happens?
ABean is not created
BBean is created anyway
CApplication crashes
DBean is created with default values
Which annotation prevents bean creation if another bean of the same type exists?
A@ConditionalOnMissingBean
B@ConditionalOnProperty
C@ConditionalOnClass
D@Component
Why use conditional bean creation in Spring Boot?
ATo avoid using annotations
BTo always create all beans
CTo create beans only when needed
DTo slow down application startup
Describe how you can use conditional annotations to control bean creation in Spring Boot.
Think about checking properties or classes before creating beans.
You got /4 concepts.
    Explain the difference between @ConditionalOnProperty and @ConditionalOnMissingBean.
    One looks at config, the other at existing beans.
    You got /3 concepts.