Q1. What problem does Spring Boot solve over plain Spring?
Short answer: Auto-configuration, starters and an embedded server remove boilerplate and speed up development.
Strong answer: Spring Boot layers convention over configuration on top of Spring: auto-configuration wires sensible defaults from the classpath, starter dependencies bundle what you need, an embedded server (Tomcat/Netty) makes apps self-contained, and Actuator adds production endpoints. You focus on business logic instead of XML and manual wiring — current to Spring Boot 4.1 on Spring Framework 7.
Likely follow-up: How does auto-configuration decide what to configure?
What the interviewer is checking: Understanding of what Boot actually adds.
Common mistake: Thinking Spring Boot is a different framework rather than Spring plus conventions.
Q2. How does Spring dependency injection work, and which injection type is preferred?
Short answer: The container manages beans and injects dependencies; constructor injection is preferred.
Strong answer: Spring’s IoC container creates and wires beans by type (and qualifier). Constructor injection is preferred because it makes dependencies explicit, supports immutability and final fields, and fails fast if a dependency is missing — unlike field injection, which hides dependencies and complicates testing.
Likely follow-up: Why is field injection discouraged?
What the interviewer is checking: DI best-practice awareness.
Common mistake: Defaulting to @Autowired field injection everywhere.
Q3. Explain the bean lifecycle and common bean scopes.
Short answer: Beans are created, wired, initialized (@PostConstruct), used, then destroyed; scopes include singleton and prototype.
Strong answer: The container instantiates a bean, injects dependencies, runs initialization callbacks (@PostConstruct/InitializingBean), serves it, and runs destruction callbacks on shutdown. Default scope is singleton (one per context); prototype creates a new instance per request; web scopes include request and session. Most beans are stateless singletons.
Likely follow-up: What’s the risk of putting mutable state in a singleton bean?
What the interviewer is checking: Lifecycle and concurrency awareness.
Common mistake: Storing per-request mutable state in a singleton.
Q4. How do you build a REST API in Spring Boot?
Short answer: @RestController with mapping annotations, DTOs, validation, and proper status codes.
Strong answer: Use @RestController and @GetMapping/@PostMapping etc., accept and return DTOs (not entities), validate input with @Valid/Bean Validation, handle errors centrally with @ControllerAdvice, and return correct HTTP status codes. Add pagination for collections and document with OpenAPI. Keep controllers thin and push logic into services.
Likely follow-up: Why return DTOs instead of JPA entities?
What the interviewer is checking: API design maturity.
Common mistake: Exposing entities directly, leaking the persistence model.
Q5. How does exception handling work in Spring Boot REST APIs?
Short answer: Centralize with @ControllerAdvice/@ExceptionHandler mapping exceptions to responses.
Strong answer: A @RestControllerAdvice class with @ExceptionHandler methods maps exceptions to consistent error responses and status codes, keeping controllers clean. Combine with a standard error body and validation-error handling. This centralizes cross-cutting error behavior instead of try/catch in every controller.
Likely follow-up: How do you return a 404 vs 400 vs 500 appropriately?
What the interviewer is checking: Error-handling design.
Common mistake: Catching and swallowing exceptions in each controller.
Q6. How do you manage transactions with @Transactional?
Short answer: @Transactional wraps a method in a transaction with configurable propagation and rollback rules.
Strong answer: @Transactional starts/commits a transaction around a method, rolling back on runtime exceptions by default. Understand propagation (REQUIRED, REQUIRES_NEW), that it works via proxies (self-invocation bypasses it), and that checked exceptions don’t roll back unless configured. Keep transactions short and at the service layer.
Likely follow-up: Why doesn’t @Transactional work when a method calls another method in the same class?
What the interviewer is checking: Understanding of proxy-based AOP.
Common mistake: Expecting self-invocation to be transactional.
Q7. How do you secure a Spring Boot application?
Short answer: Spring Security for authentication/authorization, with JWT/OAuth2 for stateless APIs.
Strong answer: Spring Security provides a filter chain for authentication and authorization. For APIs, use stateless JWT or OAuth2/OIDC resource-server support, method-level security for fine-grained rules, HTTPS, and CSRF handling appropriate to the client. Configure least-privilege roles and validate tokens properly.
Likely follow-up: Why disable CSRF for a stateless JWT API but not for a session app?
What the interviewer is checking: Security understanding.
Common mistake: Copy-pasting security config without understanding stateless vs session.
Q8. What does Spring Boot Actuator provide for production?
Short answer: Health, metrics, info and other operational endpoints for monitoring and management.
Strong answer: Actuator exposes production endpoints — health (with readiness/liveness groups for Kubernetes), metrics (via Micrometer to Prometheus), info, env, loggers and more. It makes apps observable and manageable out of the box. Secure the endpoints and expose only what you need.
Likely follow-up: How do Actuator health groups map to Kubernetes probes?
What the interviewer is checking: Production/operability awareness.
Common mistake: Exposing all Actuator endpoints publicly.