ApplicationContext is a BeanFactory plus events, i18n, resource loading and eager singleton creation.
// BeanFactory: lazy - a bean is created on the first getBean()
// ApplicationContext: eager - singletons are created at startup
var ctx = new AnnotationConfigApplicationContext(AppConfig.class);
// every singleton already exists here
OrderService s = ctx.getBean(OrderService.class);
Eager creation is a feature: a misconfigured bean fails at startup
rather than on the first request in production.
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-08-11