skip to content

Configuration & Component Model

The annotation model you use daily to declare beans: stereotypes, @Configuration classes with @Bean methods, component scanning and filters, and @Import with selectors and registrars. Interviewers probe here to see whether you know the difference between declaring a bean and making Spring find it.

part ofSpring Frameworkoverview, primer and where to startread it →
on this pageshow

questions

page 2 of 2

Walk through how a custom @EnableXxx annotation works end-to-end using @Import, and the constraints selectors/registrars operate under.

level: principalimportance: should knowfreq 22%

basics

~20 s

An @EnableXxx annotation is a custom annotation meta-annotated with @Import pointing at a @Configuration class, an ImportSelector, or an ImportBeanDefinitionRegistrar. When you put @EnableXxx on your config, ConfigurationClassPostProcessor follows the @Import and applies the referenced configuration, passing along the annotation's attributes.

open as a page

When would you write a custom @Conditional Condition versus using @Bean logic, @Profile, or a factory, and what are the practical limitations of @Conditional?

level: middleimportance: nice to knowfreq 25%

basics

~20 s

Use @Conditional when whether a bean definition exists at all should depend on the environment, classpath, or other beans — decided at startup. If you just need to choose an implementation at runtime, put logic inside the @Bean method or use a factory instead.

open as a page

What is the danger of a partially-built index across a multi-jar classpath, and how does spring.index.ignore relate to it?

level: seniorimportance: nice to knowfreq 8%

basics

~20 s

If only some jars ship a spring.components file, Spring still switches to index mode, but components in the un-indexed jars can be missed. To be safe you either index every module or set spring.index.ignore=true to force full scanning everywhere.

open as a page

How would you index a custom stereotype annotation, and how do you weigh the candidate index against Spring Boot AOT and plain scanning today?

level: principalimportance: nice to knowfreq 6%

basics

~20 s

Meta-annotate your custom stereotype with @Indexed (and usually @Component) so the indexer records classes using it. Weigh the index against Spring Boot 3 AOT: AOT largely supersedes it, so the index mainly helps large classic Spring apps where you control the whole build.

open as a page

What are the practical constraints and costs of CGLIB-based @Configuration enhancement, and how do they influence design in Kotlin and native-image builds?

level: principalimportance: nice to knowfreq 26%

basics

~20 s

Full-mode @Configuration is CGLIB-subclassed, so the class can't be final and @Bean methods can't be private/final. It adds startup cost and needs runtime bytecode, which hurts GraalVM native images. Kotlin needs the all-open plugin; teams often prefer proxyBeanMethods=false with parameter injection.

open as a page

Under the hood, how does Spring discover stereotype-annotated classes and assign bean names, and how can you customize both?

level: principalimportance: nice to knowfreq 25%

basics

~20 s

Component scanning uses ClassPathScanningCandidateComponentProvider with an AnnotationTypeFilter for @Component to find candidates in the base packages, reading bytecode via ASM (no class loading). AnnotationBeanNameGenerator names each bean (uncapitalized class name, or the stereotype's value). You customize with @ComponentScan filters, nameGenerator, and scopeResolver.

open as a page

showing 31–36 of 36