Skip to main content
InterviewHubPRO
Section Overview
Q14

Question 14 of 50

Part 2: Persistence, Transactions & Security (11 - 24)

28%
Spring Boot & Microservices (50 Qs)•Part 2: Persistence, Transactions & Security (11 - 24)

How do you prevent and resolve circular dependencies in Spring Boot?

mid LevelState ManagementSecurity & AuthDatabases & SQL

In Simple Words: A circular dependency occurs when Bean A requires Bean B, and Bean B requires Bean A:

  1. Best Fix (Architectural): Refactor code to extract shared logic into a third service (Bean C).
  2. Event-driven: Replace direct call with Spring ApplicationEvent.
  3. Lazy initialization: Annotate one injection with @Lazy, causing Spring to inject a proxy rather than fully initializing both simultaneously.
  4. Note: Spring Boot 2.6+ disables circular references by default.