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 pageshowhide
explore
- 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
questions
page 2 of 2Walk through how a custom @EnableXxx annotation works end-to-end using @Import, and the constraints selectors/registrars operate under.
basics
~20 sAn @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.
When would you write a custom @Conditional Condition versus using @Bean logic, @Profile, or a factory, and what are the practical limitations of @Conditional?
basics
~20 sUse @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.
What is the danger of a partially-built index across a multi-jar classpath, and how does spring.index.ignore relate to it?
basics
~20 sIf 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.
How would you index a custom stereotype annotation, and how do you weigh the candidate index against Spring Boot AOT and plain scanning today?
basics
~20 sMeta-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.
What are the practical constraints and costs of CGLIB-based @Configuration enhancement, and how do they influence design in Kotlin and native-image builds?
basics
~20 sFull-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.
Under the hood, how does Spring discover stereotype-annotated classes and assign bean names, and how can you customize both?
basics
~20 sComponent 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.
showing 31–36 of 36