Java Zero to All All questionsPractise free
Interview questions › Spring & Spring Boot › IoC, DI & Bean Lifecycle

How does Spring handle circular dependencies, and why is a constructor cycle a design smell rather than something to patch with @Lazy?

Level III · MidIoC, DI & Bean Lifecycle
Short answer

Spring can resolve a setter/field-injection cycle using its three-level singleton cache that exposes early bean references, but a pure constructor-injection cycle can't be satisfied and the context fails to start with BeanCurrentlyInCreationException.

Explanation

You can break it with @Lazy, setter injection, or an ObjectProvider, but those just hide that two beans are mutually responsible for each other. The senior move is to refactor: extract the shared logic into a third collaborator or publish an event, because a cycle usually signals a missing abstraction or a layering violation.

Common mistakes
  • Enabling spring.main.allow-circular-references to hide a design problem.
  • Not refactoring by extracting a third bean or using events.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for IoC, DI & Bean Lifecycle.

Practise free

More on IoC, DI & Bean Lifecycle