A circular dependency occurs when two or more Spring beans depend on each other directly or indirectly during object creation. Because each bean requires the other to be instantiated first, Spring cannot complete the dependency injection process, which may result in application startup failure.
Bean A → Depends on Bean B
Bean B → Depends on Bean A
Spring cannot determine which bean should be created first.
Bean A → Bean B
Bean B → Bean C
Bean C → Bean A
This also creates a dependency cycle.
@Service
public class OrderService {
private final PaymentService paymentService;
public OrderService(
PaymentService paymentService) {
this.paymentService =
paymentService;
}
}
@Service
public class PaymentService {
private final OrderService orderService;
public PaymentService(
OrderService orderService) {
this.orderService =
orderService;
}
}Circular reference involving
OrderService and PaymentService
This creates a circular dependency.
This removes the dependency cycle completely.
Avoid circular dependencies whenever possible. If they appear, they often indicate a design issue and can usually be eliminated through proper separation of responsibilities.
A concise interview answer is: A circular dependency occurs when two or more Spring beans depend on each other for creation. For example, Bean A depends on Bean B and Bean B depends on Bean A. This can prevent Spring from creating the beans, especially when using constructor injection. The preferred solution is to redesign the application to remove the dependency cycle, although @Lazy and setter injection can be used as temporary fixes.
Last updated: 11 November 2026
Previous question: When should you use BeanFactory, and when should you use ApplicationContext?
Next question: What are the different ways to resolve circular dependencies in Spring Boot?