Spring Boot Interview Questions and Answers (2026 Edition)
Spring Boot questions haven't changed much in a decade — which is exactly why interviewers now probe the corners candidates skip: how auto-configuration actually works, what the annotations expand to, and how you test slices of the app. The 2026 edition, with Boot 3.x notes throughout.
1. How does auto-configuration actually work?
Answer: @EnableAutoConfiguration (inside @SpringBootApplication) loads configuration classes listed in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports. Each one is guarded by @ConditionalOn… annotations — e.g. DataSourceAutoConfiguration only activates when a JDBC driver is on the classpath and you haven't defined your own DataSource bean (@ConditionalOnMissingBean). The one-liner: "Classpath + conditions + back-off when I define my own bean." Follow-up: "How do you exclude one?" — @SpringBootApplication(exclude = DataSourceAutoConfiguration.class).
2. What does @SpringBootApplication expand to?
@SpringBootConfiguration // marks it as a @Configuration class
@EnableAutoConfiguration // the magic above
@ComponentScan // scans the package of the annotated class DOWNWARD
public class ShopApplication { ... }
Answer: three annotations. The trap: @ComponentScan only scans the annotated class's package and sub-packages — which is why the main class sits at the root package. Put it in a sub-package and half your beans silently vanish.
3. What are starters, really?
Answer: a starter is just a POM — a curated dependency set plus the auto-configuration that wires it. spring-boot-starter-web pulls in Spring MVC, Jackson, validation, and an embedded Tomcat, all version-aligned by the Boot BOM. The interview point: starters exist so you never hand-manage thirty dependency versions again.
4. properties vs YAML vs @ConfigurationProperties?
// application.yml
shop:
max-discount: 20
supported-regions:
- IN
- US
// type-safe binding — prefer this over @Value sprawl
@ConfigurationProperties(prefix = "shop")
record ShopProps(int maxDiscount, List<String> supportedRegions) {}
Answer: YAML wins for hierarchical config; @ConfigurationProperties wins for type safety, validation, and IDE completion over scattered @Value("${…}"). Profiles (application-prod.yml) select per-environment values. Follow-up: "Where does config come from, in priority order?" — command-line args > env vars > profile-specific files > application.yml > defaults.
5. What is the Actuator, and what do you expose in production?
Answer: production-ready endpoints under /actuator: health, metrics, info, env. In production you expose health (liveness/readiness for Kubernetes) and metrics (Prometheus scraping) — and never env or heap dumps publicly, since they leak secrets. Custom health checks implement HealthIndicator.
6. @SpringBootTest vs @WebMvcTest vs @DataJpaTest?
Answer: slice tests. @SpringBootTest boots the whole context (slow, for integration tests); @WebMvcTest loads only the web layer with a MockMvc (fast controller tests, mock the service); @DataJpaTest loads only JPA with an in-memory DB (repository tests). The interviewer's real question: "Do you know what NOT to load?"
7. How do you change the embedded server or port?
Answer: port is server.port=8081. Swap Tomcat for Jetty/Undertow by excluding spring-boot-starter-tomcat and adding the Jetty starter — auto-configuration picks it up with zero code changes. That's the payoff of the design from question 1.
8. What shipped in Spring Boot 3.x that I should know?
- Java 17 baseline, Jakarta EE —
javax.*becamejakarta.*; old libraries break until updated. The most common migration gotcha. - GraalVM native images — compile to a native binary: ~50ms startup, tiny memory. The trade-off: longer builds and reflection hints.
- Observability built in — Micrometer + tracing wired by default; metrics and traces without extra setup.
9. How does a request actually flow? (the "draw it" question)
Answer: embedded Tomcat → DispatcherServlet → HandlerMapping finds your @RestController method → argument resolvers bind the request → interceptors → your method → HttpMessageConverter (Jackson) serializes the return value → response. Say it in that order and you've answered 90% of "explain Spring MVC" questions.
In this series
- Java 17 to 21 Interview Questions: Records, Pattern Matching, Virtual Threads — records, pattern matching, virtual threads.
- Spring Boot Interview Questions and Answers (2026 Edition) (this post) — auto-configuration to actuators.
- Java Multithreading and Concurrency Interview Questions: Deep Dive — volatile, locks, deadlocks, pools.
- Microservices Interview Questions for Java Developers — decomposition, resilience, sagas.
More: Java Interview Prep hub — the full collection of Java interview questions on JavaMakeUse.
Comments
Post a Comment