Spring Boot interview questions
Spring Boot Interview Questions for Backend Engineers
Spring Boot interviews often test whether you understand what the framework is doing around your application. Prepare to explain dependency injection, transactions, persistence, web request handling, testing, security, and production operations.
Framework and dependency-injection questions
Start with the container and configuration model, then connect it to how services are composed and tested.
How does Spring Boot auto-configuration work?
Starters put libraries on the classpath, and auto-configuration classes create beans conditionally using annotations like @ConditionalOnClass and @ConditionalOnMissingBean. If you define your own bean of the same type, the default backs off.
What is the difference between @Component, @Service, @Repository, and @Bean?
The first three mark classes for component scanning; @Repository also translates persistence exceptions into Spring's DataAccessException hierarchy. @Bean goes on a method in a @Configuration class and is how you register objects you don't own, such as third-party clients.
Why is constructor injection preferred over field injection?
Dependencies become explicit and can be final, the object can never exist half-built, and you can create it in a unit test without a Spring context. Field injection hides dependencies and needs reflection to test.
What happens when a Spring Boot application starts?
SpringApplication prepares the environment and loads properties, creates the application context, runs component scanning and auto-configuration, creates singleton beans and their dependencies, starts the embedded web server, and finally runs any ApplicationRunner and CommandLineRunner beans.
Web, data, and transaction questions
Backend interviews commonly move from controllers into persistence and transaction boundaries.
How do you validate a request body in a REST controller?
Put Bean Validation constraints such as @NotNull or @Size on the DTO fields and mark the controller parameter with @Valid. Failures raise MethodArgumentNotValidException, which a @ControllerAdvice can turn into a consistent 400 response.
Why does @Transactional sometimes not work?
It works through a proxy, so a call from one method to another in the same class skips it, and private methods aren't intercepted. By default it also rolls back only on unchecked exceptions unless you set rollbackFor.
What is the JPA N+1 problem and how do you fix it?
Loading N parents and then lazily touching each one's association fires one query for the list plus one per parent. Fix it with a fetch join, an @EntityGraph, or batch fetching, and catch it early by logging SQL in tests.
How do you handle exceptions consistently across controllers?
Put @ExceptionHandler methods in a @RestControllerAdvice class that maps exception types to status codes and one standard error body. Spring Boot 3 also supports RFC 7807 ProblemDetail responses out of the box.
Production and testing follow-ups
For experienced roles, prepare for Actuator, metrics, security filters, integration testing, connection pools, retries, circuit breakers, asynchronous work, and how you would investigate a slow Spring service.
Unit test, slice test, or integration test?
Unit tests build the class directly with mocks and run in milliseconds. Slice tests such as @WebMvcTest or @DataJpaTest load one layer. @SpringBootTest loads the whole context, ideally against real dependencies via Testcontainers. Write mostly unit tests and a few of the others.
What does Actuator give you in production?
Health, info, and metrics endpoints, with Micrometer exporting metrics to systems like Prometheus. The liveness and readiness health groups map directly to Kubernetes probes. Expose only what you need and secure the rest.
How does a request pass through Spring Security?
It goes through a chain of servlet filters before reaching the DispatcherServlet. Authentication filters build an Authentication object and store it in the SecurityContext, then authorization rules decide whether the request may reach the controller.
A Spring endpoint is slow. Where do you look?
Start with traces or metrics to see where the time goes. Common causes are slow or N+1 queries, an exhausted HikariCP connection pool, calls to other services without timeouts, and saturated thread pools.
Common questions
Why can @Transactional fail unexpectedly?
Common reasons include self-invocation bypassing the proxy, wrong propagation assumptions, exceptions that do not trigger rollback by default, or performing work outside the proxied transaction boundary.
Is Spring Boot knowledge enough for a backend interview?
Usually not. Combine it with Java, SQL and databases, API design, caching, concurrency, distributed systems, testing, observability, and system design.