Circular Dependency in Spring Beans
App fails to start with circular dependency error. Two or more beans reference each other creating an unsolvable dependency chain.
Spring can't instantiate beans if they depend on each other.
Error Messages You Might See
Common Causes
- Service A @Autowired Service B, Service B @Autowired Service A
- Controller depends on Service that depends on Controller
- Configuration class circular references
- Event listeners creating implicit dependencies
How to Fix It
Refactor to break cycle: extract common functionality to third service. Use @Lazy to defer one bean creation. Use constructor injection to identify issues clearly. Use ObjectProvider
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently Asked Questions
How do I find the circular dependency?
Spring logs the bean chain showing the cycle. Refactor to eliminate it
Can @Lazy always fix this?
@Lazy defers initialization but doesn't solve underlying design issue. Refactor properly