Circular dependency occurs when two or more Spring beans depend on each other directly or indirectly, creating a dependency cycle that prevents proper bean creation. Spring Boot provides several ways to resolve such issues, but the preferred solution is to redesign the application to reduce tight coupling between components.
1. Redesign the Application (Recommended)
OrderService → PaymentService
PaymentService → OrderService
OrderService → TransactionService
PaymentService → TransactionService
This removes the circular reference completely.
2. Use @Lazy Annotation
@Service
public class OrderService {
private final PaymentService paymentService;
public OrderService(
@Lazy PaymentService paymentService) {
this.paymentService = paymentService;
}
}
@Service
public class PaymentService {
private final OrderService orderService;
public PaymentService(
@Lazy OrderService orderService) {
this.orderService = orderService;
}
}3. Use Setter Injection
@Service
public class OrderService {
private PaymentService paymentService;
@Autowired
public void setPaymentService(
PaymentService paymentService) {
this.paymentService = paymentService;
}
}4. Use Field Injection
5. Use ObjectProvider
@Autowired
private ObjectProvider<PaymentService>
paymentServiceProvider;
public void process() {
PaymentService paymentService =
paymentServiceProvider.getObject();
}6. Use ApplicationContext
@Autowired
private ApplicationContext context;
public void process() {
PaymentService paymentService =
context.getBean(
PaymentService.class);
}7. Event-Driven Communication
OrderService publishes an event.
PaymentService listens to the event.
This completely removes direct bean dependencies.
A concise interview answer is: Spring Boot resolves circular dependencies using approaches such as @Lazy, setter injection, ObjectProvider, and event-driven communication. However, the preferred solution is to redesign the application and remove tight coupling between beans. Among the available options, @Lazy is the most commonly used quick fix, while architectural refactoring is the best long-term solution.
Last updated: 11 November 2026
Previous question: What is a circular dependency in Spring?
Next question: What is the difference between @Component and @Service? Are they interchangeable?