Difference between BeanFactory and ApplicationContext in Spring Framework (original) (raw)
The difference between BeanFactory and ApplicationContext in Spring framework is another frequently asked Spring interview question mostly asked Java programmers with 2 to 4 years experience in Java and Spring. Both BeanFactory and ApplicationContext provide a way to get a bean from the Spring IOC container by calling getBean("bean name"), but there is some difference in their working and features provided by them. One difference between the bean factory and application context is that the former only instantiates bean when you call getBean() method while ApplicationContext instantiates Singleton bean when the container is started, It doesn't wait for the getBean to be called.
These interview questions are third on my list of frequently asked spring questions e.g. Setter vs Constructor Injection and What is the default scope of Spring bean. If you are preparing for a Java interview and expecting some Spring framework questions, It’s worth preparing those questions.
By the way, if you are new to the Spring framework then I also suggest you join a comprehensive and up-to-date course to learn Spring in depth. If you need recommendations, I highly suggest you take a look at Spring Framework: Beginner to Guru, one of the comprehensive and hands-on courses to learn modern Spring. It' also the most up-to-date and covers Spring 5.
P. S. - If you are new to Spring and Spring Boot and looking for a free Spring Boot online course then I also recommend you to join the Introducing Spring Boot (FREE ) course by Dan Vega on Udemy. It's one of the best free courses to learn Spring Boot for Java developers.