What is the Spring IoC Container?
Why Interviewers Ask This
Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid Spring Boot basics — a prerequisite for any developer role.
Answer
The Inversion of Control (IoC) Container is the central Spring Framework component responsible for creating, managing, configuring, and wiring application objects (beans). "Inversion of Control" means the framework manages object creation instead of the application code doing it (new MyService()). Interfaces: BeanFactory — basic container, lazy initialization; ApplicationContext — extends BeanFactory with: eager initialization, internationalization (i18n), event publishing, AOP support. In Spring Boot, the ApplicationContext is a AnnotationConfigServletWebServerApplicationContext (for web apps). Getting the context: @Autowired ApplicationContext context; context.getBean(UserService.class); or implement ApplicationContextAware. Bean creation: Spring reads: @Component annotations (component scan), @Bean methods in @Configuration classes, XML bean definitions (legacy). Creates instances using reflection, wires dependencies, applies AOP, manages lifecycle. Bean scopes: @Scope("singleton") (default) — one instance per context; @Scope("prototype") — new instance per injection/request; @Scope("request") — new per HTTP request; @Scope("session") — new per HTTP session; @Scope("application") — one per ServletContext. Lifecycle callbacks: @PostConstruct — called after injection (initialization); @PreDestroy — called before bean is destroyed (cleanup). InitializingBean.afterPropertiesSet() and DisposableBean.destroy() also work.
Common Mistake
A common mistake is memorizing definitions without understanding implications. When asked this question, go one level deeper — explain what happens when this concept is misused or ignored.