When a Spring Boot application starts, what does the IoC container do first?
Think about how Spring finds and prepares the parts of your app it manages.
The IoC container scans the classpath for classes marked with special annotations like @Component and creates their instances as beans to manage them.
After the Spring IoC container finishes initializing, what is true about the beans it manages?
Consider the default scope of beans and when dependencies are set.
By default, singleton beans are created eagerly at startup with all dependencies injected and lifecycle methods called.
Choose the correct way to define a Spring bean using constructor injection in a @Component class.
Constructor injection means passing dependencies through the constructor parameters.
Option A uses constructor injection correctly by defining a constructor with the dependency parameter. Spring will inject the Repo bean automatically.
Given this Spring bean code, why does the application fail to start?
@Component
public class MyService {
private final MyRepository repo;
public MyService() {}
}Think about how Spring injects dependencies when constructors are present.
Spring uses constructor injection by default if a constructor with parameters exists. Here, the no-arg constructor prevents injection, so the dependency is never set.
Which statement best describes how the Spring IoC container manages lifecycle callbacks like @PostConstruct and DisposableBean?
Think about when initialization and destruction happen in the bean lifecycle.
Spring calls @PostConstruct after the bean is fully created and dependencies injected. It calls DisposableBean methods before destroying singleton beans during container shutdown.