Use Case of Lazy Initialization
Loading Optional Features in a Web Application
Scenario
Problem without Lazy Initialization
Solution with Lazy Initialization
@Component
@Lazy
public class EmailNotificationService {
public EmailNotificationService() {
System.out.println("EmailNotificationService Initialized");
}
public void sendOrderConfirmation(String email, String orderId) {
System.out.println("Sending order confirmation to: " + email);
}
}Benefits of Lazy Initialization in this Case
Last updated