Core Container & IoC
The container itself: how beans are defined, discovered, injected, scoped and destroyed, plus the Environment, SpEL and event support everything else in Spring is built on. Interviewers start here because the rest of the portfolio only makes sense once you can explain the container.
part ofSpring Frameworkoverview, primer and where to startread it →on this pageshowhide
explore
- Container & Bean Definitions26 questions
- BeanFactory vs ApplicationContext5 questions
- BeanDefinition & Configuration Metadata6 questions
- FactoryBean & Indirect Bean Creation5 questions
- Configuration & Component Model36 questions
- Stereotype Annotations5 questions
- @Configuration & @Bean Factory Methods5 questions
- Component Scanning & Filters5 questions
- @Import, ImportSelector & Registrars6 questions
- Conditional Bean Registration (@Conditional)5 questions
- Compile-Time Candidate Index (@Indexed)5 questions
- Functional & Programmatic Bean Registration5 questions
- Dependency Injection29 questions
- Constructor vs Setter vs Field Injection5 questions
- @Autowired Resolution5 questions
- @Qualifier, @Primary & Disambiguation5 questions
- @Resource & JSR-330 (@Inject/@Named)4 questions
- Scopes & Bean Lifecycle45 questions
- Singleton & Prototype Scopes5 questions
- Web Scopes & Scoped Proxies5 questions
- Init & Destroy Callbacks5 questions
- BeanPostProcessor4 questions
- BeanFactoryPostProcessor & Registry PP5 questions
- *Aware Interfaces5 questions
- Circular Dependencies & Lazy Init6 questions
- Lifecycle, SmartLifecycle & Phased Startup5 questions
- @DependsOn Bean Ordering5 questions
- Environment, Properties & SpEL20 questions
- Environment Abstraction & @Profile5 questions
- PropertySources & @PropertySource5 questions
- @Value Injection5 questions
- Spring Expression Language (SpEL)5 questions
- Container Services32 questions
- Resource Abstraction & ResourceLoader5 questions
- Type Conversion & Formatting5 questions
- Application Events6 questions
- MessageSource & i18n5 questions
- Bean Validation (JSR-380) Integration5 questions
- Data Binding, DataBinder & BeanWrapper6 questions
- Scheduling, Async & Caching36 questions
- Async Method Execution (@Async)6 questions
- Cache Abstraction5 questions
- Task Scheduling (@Scheduled)5 questions
- Async Exception Handling5 questions
- Programmatic & Dynamic Scheduling5 questions
- TaskDecorator & Context Propagation5 questions
questions
224 · 7 sectionsWhat is a BeanDefinition in Spring, and what information does it hold?
basics
~20 sA BeanDefinition is Spring's recipe for a bean: it stores metadata like the class name, scope, whether it's lazy, its constructor arguments and property values, and dependencies — the container reads it to create the actual bean instance.
What is the difference between BeanFactory and ApplicationContext in Spring?
basics
~20 sBoth are Spring IoC containers that create and wire beans. ApplicationContext is a superset of BeanFactory: it adds features like event publishing, internationalization, easy resource loading, and automatic BeanPostProcessor handling, and it eagerly creates singletons at startup.
What is an ApplicationContext, and what are the main concrete implementations you would instantiate?
basics
~10 sApplicationContext is Spring's IoC container that creates, wires, and manages beans. Common implementations: AnnotationConfigApplicationContext (Java/annotation config), ClassPathXmlApplicationContext (XML config), and GenericApplicationContext (flexible, programmatic registration).
What is a Spring FactoryBean and how does it differ from an ordinary bean?
basics
~20 sA FactoryBean is a bean whose job is to build another object. When you look it up or inject it by name, Spring hands you what its getObject() method returns, not the FactoryBean instance itself.
What is a parent-child (hierarchical) ApplicationContext in Spring, and which direction does bean visibility flow between the two levels?
basics
~20 sA child ApplicationContext can be linked to a parent. Beans defined in the parent are visible to the child, but beans defined in the child are NOT visible to the parent. Visibility flows one way: parent-to-child.
What does @ComponentScan do, and how do you tell it which packages to scan?
basics
~10 s@ComponentScan tells Spring to search packages for classes annotated with @Component (and @Service, @Repository, @Controller) and register them as beans. You point it at packages with basePackages, e.g. @ComponentScan(basePackages = "com.app").
What is @Conditional and the Condition interface in Spring, and how do you use them to register a bean only under certain circumstances?
basics
~10 s@Conditional is an annotation you put on a @Bean or @Configuration. It points to a class implementing the Condition interface, whose matches() method returns true/false. Spring registers the bean only when matches() returns true.
What are @Configuration and @Bean, and how do you use them to define a Spring bean?
basics
~10 s@Configuration marks a class as a source of bean definitions. Inside it, a method annotated with @Bean returns an object that Spring registers as a bean in the application context, managing its lifecycle.
What is functional (programmatic) bean registration in Spring, and how does it differ from declaring beans with @Bean or @Component?
basics
~10 sIt registers beans by calling code — e.g. context.registerBean(MyService.class, MyService::new) — instead of using @Component scanning or @Bean methods. You give Spring a name, a type, and a lambda that creates the instance.
What is Spring's @Import annotation and what kinds of classes can you import with it?
basics
~10 s@Import lets one Java @Configuration class pull in beans defined in another. You can import other @Configuration classes, ImportSelector or ImportBeanDefinitionRegistrar implementations, and (since Spring 4.2) plain component classes.
What does @Autowired do, and what does it mean that Spring resolves it "by type"?
basics
~10 s@Autowired tells Spring to inject a dependency automatically. "By type" means Spring looks in its container for a bean whose type matches the field, constructor parameter, or setter parameter, and wires that bean in.
What problem does method injection (@Lookup / lookup-method) solve when a singleton bean depends on a prototype bean?
basics
~10 sA singleton is created once, so a prototype injected normally is captured only once and reused forever. Method injection lets the singleton ask the container for a fresh prototype on every call.
How do you inject a dependency into a Spring bean that may not exist in the context, without the application failing to start?
basics
~10 sMake the dependency optional. Use Optional<T>, or @Autowired(required=false), or ObjectProvider<T>. If no bean exists Spring injects an empty Optional / null / an empty provider instead of throwing NoSuchBeanDefinitionException.
What does @Primary do, and when would you reach for it?
basics
~20 s@Primary marks one bean as the default choice when several beans of the same type exist. If an injection point doesn't say which one it wants, Spring picks the @Primary one instead of throwing an error.
What is the difference in default injection semantics between @Resource and @Autowired?
basics
~10 s@Autowired matches a bean by its type first. @Resource (from jakarta.annotation) matches by name first, defaulting to the field or setter property name.
What is a BeanFactoryPostProcessor, and at what point in the container lifecycle does it run?
basics
~10 sA BeanFactoryPostProcessor is a Spring hook that runs after the container reads all bean definitions but before it creates any beans. It can change the definitions (metadata), for example resolving ${...} placeholders.
What is a BeanPostProcessor in Spring and when do its methods run?
basics
~10 sA BeanPostProcessor is a Spring extension point with two callbacks that run on every bean after it is constructed and dependencies are injected — one just before the bean's init method, one just after.
What is the difference between the default singleton scope and prototype scope in Spring?
basics
~10 sA singleton bean is created once per Spring container and shared everywhere. A prototype bean gives a brand-new instance every time it is requested or injected. Singleton is the default.
What is a circular dependency between Spring beans, and how does Spring's handling differ between setter/field injection and constructor injection?
basics
~20 sA circular dependency is when bean A needs B and B needs A. Spring can resolve this for setter/field injection (it injects a half-built A into B), but constructor injection fails because neither bean can be built first.
What is the @DependsOn annotation in Spring and what problem does it solve?
basics
~10 s@DependsOn forces named beans to be created (fully initialized) before the annotated bean. It expresses an initialization-order dependency between beans that have no direct injection relationship.
What is a Spring profile, and how do you activate one?
basics
~10 sA profile is a named group of beans/config that is only registered when active. Mark beans with @Profile("dev"). Activate by setting the property spring.profiles.active=dev (property file, env var, or JVM flag).
What is Spring's Environment / PropertySources abstraction, and what does @PropertySource do?
basics
~20 sThe Environment holds an ordered list of PropertySources (files, JVM system properties, OS env vars). getProperty() searches them in order. @PropertySource loads a .properties file and adds it as one more source so its keys become available.
What is the Spring Expression Language (SpEL) and where do you commonly use it in a Spring application?
basics
~10 sSpEL is a small expression language that Spring evaluates at runtime. You write expressions inside #{...} — often in @Value — to compute values, call methods, read bean properties, or reference other beans.
How does @Value with a ${...} placeholder work, and how do you supply a default when the property is missing?
basics
~10 s@Value("${my.prop}") injects the value of property my.prop from the environment into a field or parameter. Use ${my.prop:fallback} to supply a default when the property is not set.
What is Spring's Environment abstraction, and how does it relate to profiles and properties?
basics
~10 sEnvironment is a container the context exposes that models two things: which profiles are active, and a hierarchy of property sources. You inject it to read properties (getProperty) or check profiles (getActiveProfiles / acceptsProfiles).
How do you publish and receive an application event in Spring?
basics
~10 sInject ApplicationEventPublisher and call publishEvent(event). Receive it with a method annotated @EventListener whose single parameter matches the event type. Spring calls that method when a matching event is published.
What is Bean Validation (JSR-380) and how does Spring expose a Jakarta Validator you can inject?
basics
~10 sBean Validation is a standard for declaring rules on fields with annotations like @NotNull and @Size. Spring's LocalValidatorFactoryBean builds a Validator you can inject and call validate() on.
What is Spring's ConversionService, and how does it relate to converting a String from @Value into a typed field like an int or Duration?
basics
~10 sConversionService is Spring's central component for converting one type to another (e.g. String to int). When @Value injects a text value, Spring uses it to coerce the String into the field's declared type.
What is Spring's DataBinder and what problem does it solve?
basics
~10 sDataBinder takes a bag of name/value pairs (like form fields) and sets them onto a target object's matching properties. It collects any problems in a BindingResult instead of throwing.
What is Spring's MessageSource, and how do you use getMessage to resolve a localized message with arguments?
basics
~20 sMessageSource is Spring's interface for resolving text by a code for a given Locale. You call getMessage(code, args, locale); args fill placeholders like {0} in the properties file, so one code renders in different languages.
What happens to an exception thrown inside a void @Async method, and how is that different from a normal (synchronous) method call?
basics
~20 sIn a synchronous call the exception bubbles up to the caller. In a void @Async method it runs on another thread, so the caller never sees it — Spring catches it and, by default, just logs it.
What does @Async do in Spring, and what must you do to switch it on?
basics
~10 s@Async marks a method so Spring runs it on a separate thread instead of the caller's thread. It only works if you add @EnableAsync (or Boot's equivalent) to a configuration class first.
What does @EnableCaching do, and how does @Cacheable turn a method into a cached method?
basics
~20 s@EnableCaching switches on Spring's caching support (an AOP proxy). @Cacheable on a method means: before running it, look in the named cache by key; if found, return the cached value and skip the method; if not, run it and store the result.
What are the built-in CacheManager implementations Spring ships, and when would you use each?
basics
~10 sSpring provides ConcurrentMapCacheManager (in-memory maps, good for tests), CaffeineCacheManager (Caffeine with eviction/TTL, common in prod), NoOpCacheManager (disables caching), CompositeCacheManager (combines several), and JCacheCacheManager (JSR-107 providers).
What is Spring's TaskDecorator, and why is it needed when running work on a thread pool like ThreadPoolTaskExecutor?
basics
~20 sTaskDecorator is an interface with one method, decorate(Runnable), that wraps every task before a ThreadPoolTaskExecutor runs it. You use it to carry thread-local context (like logging MDC or the logged-in user) from the calling thread onto the pool thread.