Spring Boot Interview Questions
Spring Boot interviews mix framework mechanics (what happens at startup) with practical judgement (how you would structure and debug a service). These questions cover both.
Boot fundamentals
What does @SpringBootApplication do?
It combines @Configuration (the class can declare beans), @EnableAutoConfiguration (configure beans based on the classpath and properties) and @ComponentScan (find components in the package and below). Placing the main class in a root package matters because scanning starts there.
How does auto-configuration work?
Auto-configuration classes are listed in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports and are guarded by conditions such as @ConditionalOnClass and @ConditionalOnMissingBean. If you define your own bean of that type, the default backs off. Run the app with --debug to print the conditions report.
What are starters?
Starters are dependency descriptors that bring in a curated, version-compatible set of libraries for a purpose, for example spring-boot-starter-web or spring-boot-starter-data-jpa. They save you from managing individual versions.
Constructor injection or field injection?
Prefer constructor injection. Dependencies can be final, the class is easy to unit test without a container, and missing dependencies fail fast. Field injection hides dependencies and requires reflection or the container to set them.
Configuration and operations
How do profiles and externalised configuration work?
Properties come from several sources with a defined precedence, with command-line arguments and environment variables overriding application.properties/yml. Profiles (spring.profiles.active) select profile-specific files such as application-prod.yml and conditionally register beans with @Profile.
What is Spring Boot Actuator?
Actuator adds production endpoints such as health, info and metrics. Expose only what you need, and secure the endpoints, because they can reveal internals. Health groups are commonly used for liveness and readiness probes.
Web, data and transactions
How do you handle exceptions globally in a REST API?
Use @RestControllerAdvice with @ExceptionHandler methods that map exceptions to a consistent error response and status code, instead of try/catch blocks in every controller.
@RestControllerAdvice
class ApiExceptionHandler {
@ExceptionHandler(NotFoundException.class)
ResponseEntity<ApiError> notFound(NotFoundException ex) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(new ApiError("NOT_FOUND", ex.getMessage()));
}
}Why might @Transactional not work?
Transactions are applied through proxies. Calling a @Transactional method from another method in the same class bypasses the proxy, and private or final methods cannot be proxied in the usual way. By default only unchecked exceptions trigger rollback; use rollbackFor for checked ones.
What is the N+1 query problem and how do you fix it?
Loading a list of entities and then lazily loading a relationship for each one runs one query for the list plus N more. Fix it with a fetch join, @EntityGraph or a dedicated projection query, and verify with SQL logging.
Singleton beans are shared across requests. What does that mean for state?
The default scope is singleton, so one instance serves all threads. Keep singleton beans stateless, or make any shared state thread-safe, and use request or prototype scope only when you really need per-request state.
Practice this on Quick Tech Learners
Reading answers is only the first step. Quick Tech Learners lets you turn Spring Boot and backend concepts into active practice once you create an account and sign in.
- Interview Insights: browse interview questions shared by the community and filter them by topic tag.
- Practice Quiz: choose the concepts you want to revise, answer questions, and review how you did.
- Coding Practice: write and run code in a browser editor against test cases. Pick a language, a difficulty band from Beginner to Expert, and either Practice mode (with hints) or Interview mode.
- Study Plan and reports: set the topics you are preparing, then check performance, mastery and readiness reports to see where the gaps are.
- Share Interview Question: add a question you were asked so other learners can practise it.