Spring Boot interviews test whether you know what Boot does for you: auto-configuration, starters, dependency injection, REST controllers, JPA and transactions, Spring Security, testing and Actuator. As of 11 November 2026 the latest release is Spring Boot 4.1.2, and 3.x is still common in existing code. These 40 questions have short model answers.
These questions are grouped by topic and answered for Spring Boot 3.x and 4.x. Facts were checked on 11 November 2026 against docs.spring.io, the Spring Boot release notes, api.spring.io and Maven Central. Java snippets were proofread, not compiled. Boot 4 marks an answer that changed in the 4.0 generation.
Masai's earlier Common Spring Boot Interview Questions and Tips is a shorter 2023 list. Use this page for version-specific detail, and Java syntax basics if the language itself is the gap.
Which Spring Boot version to prepare for
| Release line | Open-source support ends | What to know |
|---|---|---|
| 3.5.x | 30 June 2026 | Last 3.x line. Boot's migration guide says to reach the latest 3.5.x before moving to 4.0 |
| 4.0.x | 31 December 2026 | Released 20 November 2025 on Spring Framework 7 and Jakarta EE 11. Java 17 is the minimum and Java 25 is supported |
| 4.1.x | 31 July 2027 | 4.1.2 is the latest release on Maven Central. Adds gRPC support and SSRF filtering for HTTP clients |
| 4.2.x | 31 December 2027 (planned) | A release candidate is on Maven Central; the final release is due in the November 2026 window |
Support dates come from api.spring.io. Boot ships a new major or minor version every six months, in May and November, and minors get at least 12 months of support. Where an answer differs between 3.x and 4.x, it says so.
Core Spring and Spring Boot (Q1 to Q6)
- Q1. What is Spring Boot, and how does it differ from the Spring Framework? Spring Framework supplies the container, dependency injection, MVC, data access and transactions. Spring Boot adds starters, auto-configuration, an embedded server, externalised configuration and Actuator, so an app runs with
java -jarand no XML or separate server. - Q2. What does
@SpringBootApplicationdo? It combines@SpringBootConfiguration,@EnableAutoConfigurationand@ComponentScan. Component scanning starts at the annotated class's package, so keep the main class in the root package. - Q3. What is dependency injection, and why prefer constructor injection? The container creates objects and supplies their collaborators. The Spring team advocates constructor injection because components can be immutable, required dependencies are never null and objects arrive fully initialised. With one constructor,
@Autowiredis optional. - Q4. How do you choose between several beans of one type? Mark one
@Primary, select by name with@Qualifier, or inject a List or Map of all candidates. With several candidates and no rule, startup fails with an error. - Q5. What are bean scopes? Singleton is the default: one instance per container. Prototype creates a new instance each time it is requested. Web-aware contexts add request, session and application scopes. Singletons are shared across threads, so keep them stateless.
- Q6. What is the difference between
@Component,@Service,@Repositoryand@Controller, and what is@Bean? All register scanned beans. The last three mark a layer, and@Repositoryalso enables persistence exception translation.@Beanis a method in a@Configurationclass that builds an object you cannot annotate, such as a third-party client.
Auto-configuration and configuration (Q7 to Q12)
- Q7. How does auto-configuration work?
@EnableAutoConfigurationloads classes annotated@AutoConfiguration, listed inMETA-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports. Each uses conditions such as@ConditionalOnClassand@ConditionalOnMissingBean, so it applies only when a library is present and you have not defined your own bean. - Q8. How do you see which auto-configurations ran, and why? Start the app with
--debugto print the conditions report, which lists matched and unmatched classes with reasons. The Actuatorconditionsendpoint shows the same once you expose it. - Q9. How do you turn off or replace an auto-configuration? Define your own bean and the default backs away, for example your own
DataSource. To exclude a class, useexcludeon@SpringBootApplicationor thespring.autoconfigure.excludeproperty. Boot 4: classes moved packages, soDataSourceAutoConfigurationis now inorg.springframework.boot.jdbc.autoconfigure. - Q10. What are starters, and what changed in Boot 4? Starters are dependency bundles named spring-boot-starter-<technology>. Boot 4 split the code into focused modules and gave most technologies their own starter and test starter, so spring-boot-starter-web became spring-boot-starter-webmvc. Classic starters ease migration.
- Q11. In what order does Boot read configuration, and what are profiles? Later sources override earlier ones: application.properties, then OS environment variables, Java system properties, then command-line arguments. Profiles add files such as application-prod.properties, activated with
spring.profiles.activeor SPRING_PROFILES_ACTIVE. - Q12.
@Valueor@ConfigurationProperties?@ConfigurationPropertiesbinds a prefix to a typed class or record, supports relaxed names and validation, and uses constructor binding when there is one parameterised constructor. Use@Valuefor a one-off value.
// application.properties: app.mail.host=smtp.example.com and app.mail.port=587
@ConfigurationProperties("app.mail")
public record MailProperties(String host, int port, @DefaultValue("true") boolean tls) { }
@SpringBootApplication
@ConfigurationPropertiesScan
public class ShopApplication {
public static void main(String[] args) {
SpringApplication.run(ShopApplication.class, args);
}
}REST and web (Q13 to Q18)
- Q13. What is the difference between
@Controllerand@RestController?@RestControlleris@Controllerplus@ResponseBody: return values are written to the response body, usually as JSON, instead of being resolved to a view name. - Q14. How do
@PathVariable,@RequestParamand@RequestBodydiffer?@PathVariablereads a URI segment such as /orders/42.@RequestParamreads a query or form parameter.@RequestBodyconverts the request body, usually JSON, into an object. Boot 4: JSON conversion uses Jackson 3, in the tools.jackson package. - Q15. How do you handle exceptions globally? Put
@ExceptionHandlermethods in a@RestControllerAdviceclass and return aProblemDetail, which Spring supports as RFC 9457. Settingspring.mvc.problemdetails.enabled=truegives standard error bodies for Spring MVC exceptions. - Q16. How do you validate request data? Add the validation starter, put Jakarta Validation annotations such as
@NotBlankand@Sizeon the request type and mark the parameter@Valid. A failure raises an exception that Spring turns into a 400 response, and you can shape the body in your advice class. - Q17.
RestTemplate,RestClient,WebClientor an HTTP interface: which to call another service? The Spring Framework 7 docs deprecateRestTemplate, and 7.1 is planned to mark it@Deprecated. UseRestClientfor blocking calls,WebClientfor reactive ones, or an@HttpExchangeinterface that Spring turns into a client. Boot 4 auto-configures those interface clients. - Q18. What is API versioning in Boot 4? Spring MVC and
WebFluxcan map requests by version, as in@GetMapping(version = "1.1"). The version is read from a header, query parameter, media type parameter or path segment. A baseline such as "1.2+" matches that version and later supported ones. An unsupported version gives a 400.
@RestControllerAdvice
class ApiErrors {
@ExceptionHandler(OrderNotFoundException.class)
ProblemDetail notFound(OrderNotFoundException ex) {
ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND, ex.getMessage());
pd.setTitle("Order not found");
return pd;
}
}Data and JPA (Q19 to Q25)
- Q19. How do JPA, Hibernate and Spring Data JPA relate? JPA is the specification and Hibernate is the implementation Boot configures (Hibernate 7.2 in Boot 4.0). Spring Data JPA writes repository implementations from interfaces, so you rarely hand-write data access code.
- Q20.
CrudRepositoryorJpaRepository?CrudRepositorygives basic create, read, update and delete.JpaRepositoryadds JPA-specific operations such as flushing and batch deletes, returns Lists and supports paging and sorting. - Q21. Derived queries or
@Query? Method names such asfindByEmailAndActiveTruebecome queries, which suits simple filters. Use@Querywith JPQL or native SQL for joins and custom projections. Pass a Pageable to get a Page, and project to DTOs for read-only screens. - Q22. How does
@Transactionalwork, and when does it silently fail? Spring wraps the bean in a proxy, so only calls through the proxy start a transaction. A method calling another method on the same object gets none. By defaultRuntimeExceptionand Error roll back, and checked exceptions do not. - Q23. What is the N+1 select problem? Loading N parents and then touching a lazy association on each fires one extra query per parent. Fix it with a JPQL
join fetch, an@EntityGraph, a DTO projection or batch fetching, and compare the SQL log before and after. - Q24. What does
spring.jpa.open-in-viewdo? For web apps Boot registersOpenEntityManagerInViewInterceptorby default, keeping the persistence context open during request handling so lazy loading works in controllers and views. Setting it to false makes you load everything you need inside the service transaction. - Q25. How should you manage the database schema? Use a migration tool such as Flyway or Liquibase, which Boot 4 supports through spring-boot-starter-flyway and spring-boot-starter-liquibase. Boot creates tables automatically only for an embedded database such as H2 or HSQL, so do not rely on ddl-auto against real data.
Security and testing (Q26 to Q34)
Security
- Q26. What does Spring Security do by default in a Boot app? Adding the security starter protects every endpoint with form login or HTTP Basic, chosen by the Accept header, and generates a user with a random password at startup. Defining your own
SecurityFilterChainbean switches off that default web security. - Q27. How do you configure rules today? Declare a
SecurityFilterChainbean and useauthorizeHttpRequestswith the lambda DSL.WebSecurityConfigurerAdapterwas removed in Spring Security 6. Rules are checked in order, so put specific matchers beforeanyRequest(). - Q28. Authentication versus authorisation, and how are passwords stored? Authentication proves who you are; authorisation decides what you may do. Store salted, adaptive hashes through a
PasswordEncodersuch as BCryptPasswordEncoder, never plain text. UsehasRoleor@PreAuthorize, which needs@EnableMethodSecurity, for access rules. - Q29. How do you secure a REST API with JWT? Add the OAuth2 resource server starter (spring-boot-starter-security-oauth2-resource-server in Boot 4) and configure an issuer or key set. Spring validates the bearer token's signature and expiry. Keep tokens short-lived and never put secrets in them.
- Q30. When do you need CSRF protection, and what is CORS? Spring Security recommends CSRF protection for any request a browser user can make, and a service used only by non-browser clients usually disables it. CORS is the browser's cross-origin rule; configure allowed origins explicitly.
@Configuration
@EnableMethodSecurity
class SecurityConfig {
@Bean
SecurityFilterChain api(HttpSecurity http) throws Exception {
http
// stateless API with bearer tokens, no cookie session, so CSRF is off
.csrf(csrf -> csrf.disable())
.authorizeHttpRequests(auth -> auth
.requestMatchers("/actuator/health").permitAll()
.requestMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated())
.oauth2ResourceServer(oauth -> oauth.jwt(Customizer.withDefaults()));
return http.build();
}
}Testing
- Q31.
@SpringBootTest,@WebMvcTestor@DataJpaTest?@SpringBootTestloads the full context, optionally on a real port, and is the slowest. Slice tests load one layer:@WebMvcTestfor controllers and@DataJpaTestfor entities and repositories. Prefer slices for speed and keep a few full tests for wiring. - Q32. How do you mock a bean, and what changed in Boot 4? Use
@MockitoBeanor@MockitoSpyBean. Boot 4 removed@MockBeanand@SpyBean.@SpringBootTestno longer providesMockMvcorTestRestTemplateby itself, so add@AutoConfigureMockMvcor@AutoConfigureTestRestTemplate. - Q33. How do you test against a real database or broker? Use Testcontainers with
@ServiceConnection, which starts a container and wires its connection details into the context. It exercises real SQL behaviour that an in-memory database can hide. - Q34. How do you test a controller? Use
@WebMvcTestwithMockMvcand a@MockitoBeanservice, or Boot 4'sRestTestClient, which can targetMockMvcor a running server. Assert status, body and validation errors, and add spring-security-test for secured routes.
// imports omitted
@WebMvcTest(OrderController.class)
class OrderControllerTest {
@Autowired MockMvc mvc;
@MockitoBean OrderService service;
@Test
void unknownOrderReturnsNotFound() throws Exception {
when(service.find(42L)).thenThrow(new OrderNotFoundException(42L));
mvc.perform(get("/orders/42"))
.andExpect(status().isNotFound());
}
}Actuator, production and microservices (Q35 to Q40)
Actuator and production
- Q35. What is Actuator, and what is exposed by default? Actuator adds production endpoints for health, metrics, environment, beans and more. Over HTTP only health is exposed by default; widen it with
management.endpoints.web.exposure.includeand protect the rest. Boot 4: liveness and readiness probes are enabled by default. - Q36. How do metrics and tracing work? Micrometer records metrics and observations, and Actuator exposes them. Boot 4 adds spring-boot-starter-opentelemetry, which exports metrics and traces over OTLP and configures the OpenTelemetry SDK.
- Q37. How do you run a Boot app efficiently in production? Package an executable jar or container image and keep graceful shutdown, which is on by default, so in-flight requests finish. On Java 21 or later,
spring.threads.virtual.enabled=truemakes the auto-configured task executor use virtual threads. Measure before and after.
Microservices
- Q38. Which Spring Cloud pieces matter, and how do versions map? Common ones are Gateway for routing, Config for central settings,
CircuitBreakerfor fallbacks and OpenFeign for client calls. Release trains map to Boot lines: Spring Cloud 2025.1 (Oakwood) lists Boot 4.0.x and 2025.0 lists 3.5.x. - Q39. How do you make service calls resilient? Set timeouts, retry only idempotent calls with back-off and add a circuit breaker. Spring Framework 7 adds
@Retryableand@ConcurrencyLimitto core, enabled with@EnableResilientMethods; the default is three retries after the first failure, one second apart. - Q40. REST calls or messaging between services? Use synchronous HTTP when the caller needs an answer now. Use Kafka or RabbitMQ when work can happen later or must survive a service being down. Messaging brings duplicates and ordering issues, so make consumers idempotent.
How interviewers evaluate answers
No company publishes its rubric, so this is our reading of the questions above, not survey data. Interviewers tend to listen for five things:
- Correctness. The right annotation, the right default and the right behaviour. Saying that only health is exposed by default beats saying Actuator exposes everything.
- Version awareness. Say which Boot line you mean. A candidate who notes
@MockBeanis gone in 4.0 shows current knowledge. - The why and the trade-off. Constructor injection gives immutability; open-in-view trades convenience for hidden queries.
- Evidence from your own work. One sentence such as 'I hit self-invocation in my project' is worth more than a memorised paragraph.
- Honest limits. 'I have not used that, I would check the reference' is better than guessing.
Build one REST API with JPA and security from the backend developer roadmap before you memorise answers, and keep the data structures and algorithms path ready for coding rounds. An assistant from the free AI coding assistants list can quiz you, but check its answers against docs.spring.io.
Frequently asked questions
What are the most asked Spring Boot interview questions?
Expect auto-configuration, @SpringBootApplication, dependency injection, @RestController, exception handling, JPA and @Transactional, Spring Security configuration, testing slices and Actuator. Questions 1, 2, 7, 13, 22 and 26 above are the ones to master first. No company publishes its question bank, so this is our reading.
What is the difference between Spring and Spring Boot?
Spring is the framework: dependency injection, MVC, data access and transactions. Spring Boot is an opinionated layer on top that adds starters, auto-configuration, an embedded server and production features, so you configure less and run with java -jar.
Is Spring Boot 4 very different from 3.x?
The core ideas are the same. The visible changes are modular starters, Jackson 3, removal of @MockBean in favour of @MockitoBean, API versioning, HTTP service clients and the OpenTelemetry starter. Java 17 is still the minimum, so most 3.x knowledge transfers, and the migration guide lists the rest.
How should a fresher prepare for a Spring Boot interview?
Build a small REST API with validation, JPA, security and tests, then explain each annotation in your own words. Learn Java collections and object-oriented basics, practise data structures and algorithms, and rehearse the 40 answers aloud until you can give each in under a minute.
Which Java version should I use with Spring Boot?
Spring Boot 4.0 requires Java 17 or later and supports Java 25, which Spring describes as the latest LTS release. Virtual threads need Java 21 or later, so learn on a recent LTS release and keep your code compatible with Java 17 if your target employer still uses it.
Do Spring Boot interviews include coding rounds?
Many companies add a coding round or online test next to framework questions, but we found no published statistics. Prepare data structures and algorithms, and be ready to write a simple REST endpoint or repository method with validation on a shared screen or in an editor.
Sources checked
- Spring Boot 4.0.0 announcement
- Boot 4.0 release notes
- Boot 4.0 migration guide
- Boot 4.1 release notes
- Support end dates
- Latest versions on Maven Central
- Auto-configuration reference
- Actuator endpoint exposure
- @Transactional behaviour
- Spring Framework 7.0 announcement
Learn this with mentors
Programmes for builders and engineers with admissions open: live classes, mentors and project work.


