Top 25 Spring MVC Interview Questions for Experienced Developers
Top 25 Spring MVC Interview Questions for Experienced Developers Work through these 15 questions out loud. Open any question for the full model answer, the trap to avoid, and the follow-up a panel usually asks.
Describe the Spring Bean lifecycle.
Container instantiates the bean, injects dependencies, runs BeanPostProcessors, then @PostConstruct or InitializingBean. Singleton lives for context lifetime; prototype creates...
How does @Transactional work?
Spring creates a proxy around @Transactional beans. Calling createOrder() from another bean starts a transaction on the thread-bound EntityManager; commit on success, rollback...
@RestController vs @Controller?
@Controller is for traditional MVC — return "user/list" view name. @RestController adds @ResponseBody so return types become JSON/XML body — standard for REST APIs. Use...
springdoc-openapi vs legacy springfox — what should new projects use?
Add springdoc-openapi-starter-webmvc-ui dependency. Annotate with @Operation, @Schema on DTOs. Disable in prod via springdoc.api-docs.enabled=false or secure endpoint. Generate...
Best practices for Spring Data pagination with Pageable?
Controller: @PageableDefault(size=20, sort="createdAt", direction=DESC) Pageable p. Cap size at 100. Admin reports: keyset pagination on id > lastId for deep pages — OFFSET...
What are common mistakes freshers make in Spring Boot projects?
```java // ❌ Wrong @RestController public class OrderController { @PostMapping("/orders") public Order create(@RequestBody Order o) { return orderRepository.save(o); // DB in...
What is AiServices, and why is it better than calling chat.completions() from a controller?
AiServices is a typed facade over ChatLanguageModel. I declare TicketAssistant with @SystemMessage and @UserMessage, register it as a singleton @Bean, and the controller never...
What is dependency injection and why does Spring use it?
DI supplies collaborators from outside the class — typically via constructor. Problem solved: tight coupling to concrete classes, hard unit tests, scattered object...
What happens if an exception occurs inside a filter or interceptor?
Exceptions in `Filter` bypass `@ControllerAdvice` unless handled. Filters run before MVC. ```java @Override protected void doFilterInternal(HttpServletRequest req,...
What is the N+1 query problem and how do you fix it?
Loading 100 orders then accessing each order's items triggers 101 queries. Fix with JOIN FETCH in JPQL, @EntityGraph on repository method, or a DTO query selecting only...
Explain JWT authentication flow in Spring Security.
POST /login with credentials → auth provider validates → issue JWT with exp/sub/roles. Subsequent requests include Bearer token. JwtAuthenticationFilter runs before...
How do you handle exceptions globally in Spring?
Create @RestControllerAdvice with @ExceptionHandler(MethodArgumentNotValidException.class) returning 400 + field map, NotFoundException → 404, generic Exception → 500 without...
How do you test Spring Boot applications?
Unit test services with Mockito — no Spring. @WebMvcTest + MockMvc for controller contract. @DataJpaTest for repository queries. @SpringBootTest + Testcontainers for critical...
How configure CORS correctly in Spring Security 6?
CorsConfiguration config = new CorsConfiguration(); config.setAllowedOrigins(List.of("https://app.example.com")); config.setAllowedMethods(List.of("GET","POST"));...
How does Spring Boot auto-configuration work?
@SpringBootApplication enables @EnableAutoConfiguration, which loads candidate configs from starters. Each auto-config uses @ConditionalOn* to register beans only when...
Spring MVC Interview Questions and Answers · Top 50 Spring MVC Interview Questions and Answers (2026 Edition) · Top 40 Spring MVC Interview Questions | Must-Prepare before interview. · Spring MVC Interview Questions Every Fresher Must Know
All interview question lists · Interview guides · Home · Support the platform