What will happen if two custom auto-configuration classes both define a bean of the same type without conditional annotations?
medium📝 component behavior Q5 of 15
Spring Boot - Advanced Patterns
What will happen if two custom auto-configuration classes both define a bean of the same type without conditional annotations?
ASpring Boot merges both beans automatically
BBoth beans will be created with different names
COnly the first bean will be created silently
DSpring Boot will fail to start due to bean definition conflict
Step-by-Step Solution
Solution:
Step 1: Understand bean conflict in Spring Boot
If two beans of the same type exist without conditions, Spring Boot cannot decide which to use and throws an error.
Step 2: Evaluate options
Options B and D are incorrect because Spring does not merge or silently ignore conflicts. Only the first bean will be created silently is incorrect because Spring fails fast.
Final Answer:
Spring Boot will fail to start due to bean definition conflict -> Option D
Quick Check:
Duplicate beans without conditions cause startup failure [OK]
Quick Trick:Avoid duplicate beans by using conditional annotations [OK]
Common Mistakes:
Assuming Spring merges duplicate beans
Expecting silent override without error
Ignoring conditional annotations
Master "Advanced Patterns" in Spring Boot
9 interactive learning modes - each teaches the same concept differently