Skip to content
Spring Boot interview 4 min read

Interview Questions

A focused set of Spring Boot interview questions grouped by topic. Each answer is concise but complete, the kind of response that signals genuine understanding rather than memorization.

Core Concepts

What is Spring Boot and how does it differ from the Spring Framework? Spring Boot is an opinionated layer on top of Spring that adds auto-configuration, starter dependencies, and an embedded server. Spring provides the IoC container and modules; Spring Boot configures them automatically so you can run a production app with almost no boilerplate.

What does the @SpringBootApplication annotation do? It is a meta-annotation combining @Configuration, @EnableAutoConfiguration, and @ComponentScan. It marks the class as a configuration source, enables auto-configuration, and starts component scanning from the class’s package.

What is Inversion of Control (IoC)? IoC means the framework controls object creation and wiring instead of your code. Spring’s ApplicationContext instantiates beans, injects their dependencies, and manages their lifecycle.

What is Dependency Injection and which type is preferred? DI supplies a class’s collaborators from outside rather than having it construct them. Constructor injection is preferred because it makes dependencies explicit, supports final fields, and works in plain unit tests.

What is a Spring bean and what is its default scope? A bean is an object managed by the Spring container. The default scope is singleton, one shared instance per application context.

What is the difference between @Component, @Service, and @Repository? All are stereotypes detected by component scanning. @Service and @Repository are specializations of @Component that convey intent; @Repository additionally enables persistence exception translation.

Auto-configuration & Starters

How does auto-configuration work? Spring Boot loads auto-configuration classes listed in META-INF/spring/...AutoConfiguration.imports. Each is guarded by @Conditional annotations (e.g. @ConditionalOnClass, @ConditionalOnMissingBean) so it only applies when relevant and never overrides your explicit beans.

What is a Spring Boot starter? A starter is a curated dependency descriptor. For example, spring-boot-starter-web brings in Spring MVC, Jackson, validation, and embedded Tomcat in compatible versions, so you avoid manual dependency management.

How do you disable a specific auto-configuration? Use @SpringBootApplication(exclude = DataSourceAutoConfiguration.class) or the spring.autoconfigure.exclude property.

How does Spring Boot manage dependency versions? Through the spring-boot-starter-parent (or the imported BOM in Gradle), which pins compatible versions, so starters declare no explicit version.

What is the role of @Conditional annotations? They make bean registration conditional on the classpath, existing beans, properties, or environment, which is the mechanism that powers smart auto-configuration.

REST

What is the difference between @Controller and @RestController? @RestController is @Controller plus @ResponseBody, so return values are serialized directly to the response body (JSON) instead of being resolved as view names.

How do you read different parts of a request? @PathVariable binds URL path segments, @RequestParam binds query parameters, and @RequestBody deserializes the request body into an object.

When should you use ResponseEntity? When you need to control the HTTP status, headers, or return an empty body, for example 201 Created with a Location header or 204 No Content on delete.

How do you validate request data? Annotate the DTO with Jakarta Bean Validation constraints (@NotBlank, @Positive) and the controller parameter with @Valid. Handle the resulting MethodArgumentNotValidException in a @RestControllerAdvice.

How do you handle exceptions globally? With a @RestControllerAdvice class containing @ExceptionHandler methods that map exception types to status codes and response bodies.

Data & JPA

What does extending JpaRepository give you? Ready-made CRUD, pagination, and sorting methods (save, findById, findAll, deleteById) with no implementation, plus support for derived and custom queries.

What are derived query methods? Repository methods whose names Spring parses into queries, e.g. findByNameAndPriceLessThan becomes a WHERE name = ? AND price < ? query.

What is the N+1 query problem and how do you avoid it? It occurs when loading a collection triggers one query per parent for its children. Avoid it with JOIN FETCH in a @Query, an entity graph, or batch fetching.

What does spring.jpa.hibernate.ddl-auto control, and what is safe in production? It controls schema generation (none, validate, update, create, create-drop). In production use validate or none with versioned migrations (Flyway/Liquibase); never update or create.

Where should @Transactional go? On service-layer methods that group repository calls into a single atomic unit of work, not on controllers or repositories.

Actuator & Production

What is Spring Boot Actuator? A production module that exposes operational endpoints, health, metrics, info, environment, and more, over HTTP or JMX for monitoring and management.

Which Actuator endpoints are most used? /actuator/health for liveness/readiness, /actuator/metrics for runtime metrics, and /actuator/info for build metadata. Most endpoints are disabled or secured by default.

How do you externalize configuration across environments? Use profile-specific files (application-prod.yml), environment variables, and command-line arguments, which override the base application.yml according to Spring Boot’s property precedence.

How do you package and run a Spring Boot app in production? Build an executable JAR (mvnw clean package) and run java -jar app.jar, or containerize it. The embedded server makes the artifact self-contained and cloud-friendly.

Tip: In interviews, pair each answer with a short “why it matters” rationale. Explaining that constructor injection aids testability, for instance, demonstrates judgment beyond rote knowledge.

Last updated June 1, 2026
Was this helpful?