Spring IoC Container Types: BeanFactory vs ApplicationContext
Fast recall
Quick revision
Core answer
Knowledge of Spring's container hierarchy and which container is actually used in production
Not knowing BeanFactory exists or thinking it's used in modern Spring Boot applications
Name specific ApplicationContext implementations like AnnotationConfigApplicationContext and their use cases
Interview-ready guide
Interview answer
Most applications, including Spring Boot apps, use an ApplicationContext. It is a BeanFactory plus higher-level facilities and it automatically recognizes post-processors and other infrastructure during refresh. A plain BeanFactory is useful for low-level or constrained container use but needs more manual setup. ApplicationContext commonly creates non-lazy singleton beans during refresh, which catches configuration errors early. That is a default behavior, not an essential definition: @Lazy can defer a singleton, prototypes are created on request, and a configurable BeanFactory can explicitly pre-instantiate singletons.
Spring IoC Container Types: BeanFactory vs ApplicationContext
Direct Answer
BeanFactory is Spring's basic bean-container interface. ApplicationContext extends it and adds an application-level programming model for events, messages, resources, environment support, and automatic discovery of many infrastructure components. The common claim that BeanFactory is always lazy and ApplicationContext is always eager is too simple: creation depends on scope, lazy flags, and whether singleton pre-instantiation is requested.
Common Mistakes & Pitfalls
- Thinking BeanFactory is still used: Freshers sometimes believe BeanFactory is a viable option for new projects. In reality, it's deprecated for most use cases — ApplicationContext is the modern standard.
- Not understanding eager vs lazy: Some think all beans are lazy by default. With ApplicationContext, singleton beans initialize at startup, which catches configuration errors early rather than at runtime.
- Manually creating ApplicationContext in Spring Boot: Writing new AnnotationConfigApplicationContext in a Spring Boot app breaks auto-configuration. SpringApplication.run creates and configures the container — never bypass it.
- Confusing container with context: Saying 'Spring context' and 'IoC container' interchangeably is fine, but know that ApplicationContext is the interface name and the container is the runtime engine it provides.
Check your understanding
Answer these without looking back at the article.
- What is the difference between BeanFactory and ApplicationContext?
- What ApplicationContext implementation does Spring Boot create?
- How do you get the ApplicationContext in a Spring bean?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.