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?
✗ Incorrect
@ConditionalOnProperty checks for a property value before creating the bean.What does
@ConditionalOnClass check before creating a bean?✗ Incorrect
@ConditionalOnClass creates a bean only if a specific class exists in the project.If a condition in
@Conditional is false, what happens?✗ Incorrect
The bean is skipped and not registered in the Spring context.
Which annotation prevents bean creation if another bean of the same type exists?
✗ Incorrect
@ConditionalOnMissingBean ensures no duplicate beans of the same type are created.Why use conditional bean creation in Spring Boot?
✗ Incorrect
Conditional creation helps optimize resources by creating beans only under certain conditions.
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.