Scrivio Interview library

Spring MVC architecture

38 questions in 10 subtopics.

DispatcherServlet

ConceptFoundations5 min read
What is the front controller pattern and how does Spring Boot register DispatcherServlet?
InternalsFoundations5 min read
Walk through what DispatcherServlet.doDispatch does for a request to a @RestController method.
DebuggingIntermediate5 min read
A request to /api/orders/ returns 404 after an upgrade to Spring Boot 3, while /api/orders works. What changed?
ScenarioAdvanced6 min read
A gateway in front of 50 MVC services adds and strips path prefixes, and services generate wrong redirect and Location URLs. How would you fix this consistently?

Handler mappings and adapters

ConceptFoundations5 min read
What do HandlerMapping and HandlerAdapter do, and why are they separate?
InternalsIntermediate6 min read
How does Spring choose between two mappings, GET /users/{id} and GET /users/me, for a request to /users/me?
DebuggingIntermediate6 min read
Startup fails with 'Ambiguous mapping. Cannot map method ... There is already ... bean method mapped'. What causes this and how do you find the conflict?
LeadershipPrincipal6 min read
Spring MVC added functional endpoints (RouterFunction) alongside annotated controllers. How would you decide whether your organisation adopts the functional style, and what is the long-term cost of supporting both?

Argument resolvers and return value handlers

CodingFoundations6 min read
Write a HandlerMethodArgumentResolver so that a controller parameter annotated @CurrentTenant Tenant tenant is filled from the X-Tenant header.
InternalsIntermediate7 min read
How is a @RequestBody parameter turned into a Java object, and where can you change the process?
CodingIntermediate6 min read
Every JSON response must be wrapped in {"data": ...} for a mobile API. Would you use a ResponseBodyAdvice or a custom return value handler? Show the approach and its pitfalls.
LeadershipAdvanced6 min read
Teams have added many custom argument resolvers, message converters and response advices, and upgrades break them. How would you control framework extensions across teams?

Filters vs interceptors

ConceptFoundations6 min read
What is the difference between a servlet Filter and a HandlerInterceptor? Give one use case for each.
CodingIntermediate7 min read
Register two filters so that a correlation id filter runs before Spring Security and a metrics filter runs after it. Show how ordering works.
DebuggingIntermediate6 min read
A HandlerInterceptor adds a response header in postHandle, but the header never appears for @RestController methods. Why?
DesignAdvanced6 min read
Cross-cutting concerns such as authentication, tenant resolution, rate limiting and request logging are implemented differently in each service, some in filters, some in interceptors, some in AOP. What standard would you set?

View resolution

ConceptFoundations5 min read
How does Spring MVC resolve a view when a @Controller method returns "orders/list", and how does this differ from a @RestController?
ScenarioIntermediate7 min read
A legacy app uses JSP views and server-side rendering, and a new team wants to build a single-page app with REST APIs on the same service. How would you structure the transition?
LeadershipPrincipal6 min read
Server-side rendering with templates fell out of favour for single-page apps and is now returning in some forms. How would you decide the long-term front-end architecture for products built on Spring, and what role should Spring MVC views play?

Request lifecycle

ConceptFoundations6 min read
Describe the full life of an HTTP request in a Spring Boot MVC application, from the socket to the response.
InternalsIntermediate6 min read
What changes in the request lifecycle when a controller returns DeferredResult or CompletableFuture?
DesignAdvanced6 min read
Your organisation has MVC services and WebFlux services. With virtual threads available, would you standardise on one stack for new services?
LeadershipPrincipal5 min read
Spring MVC has been stable for almost twenty years while the web moved to SPAs, REST, GraphQL and streaming. What does this tell you about choosing web frameworks, and when would you replace one?
LeadershipPrincipal6 min read
Your services are spread across Spring MVC versions from five years apart. How would you explain to leadership the risk of letting framework versions diverge in the web layer, and what would you do about it?

WebMvcConfigurer customization

CodingFoundations6 min read
Write a WebMvcConfigurer for a Spring Boot service that registers an interceptor for /api/** except /api/health, adds CORS for https://app.example.com on /api/**, serves static files from classpath:/ui/ under /ui/**, and adds a String-to-OrderStatus converter. Why should you not add @EnableWebMvc here?
DebuggingIntermediate6 min read
After a teammate overrode configureMessageConverters in a WebMvcConfigurer to add a CSV converter, all JSON endpoints started returning 406 or using a different date format. Explain why, and the correct way to add a converter.
DesignAdvanced6 min read
Your company has 70 Spring MVC services, each with its own WebMvcConfigurer for CORS, interceptors, converters and path matching, and behaviour differs subtly between them. Design a shared approach without blocking teams from legitimate customisation.

Async request processing

CodingFoundations7 min read
Write a Spring MVC endpoint that returns a report generated in about 10 seconds without holding the servlet thread, using Callable or DeferredResult, and configure the async timeout and the executor. What does the client see on timeout?
DebuggingIntermediate7 min read
A service returns CompletableFuture from controllers. Logs for the completion part lose the trace id and user, Spring Security's SecurityContextHolder is empty in the async code, and some requests hang until the async timeout. What is happening and how do you fix each?
LeadershipAdvanced6 min read
Your teams use DeferredResult, CompletableFuture, WebFlux Mono and virtual threads to handle slow downstream calls, and incidents show each style fails differently. What guidance would you give for new and existing services?

Form handling and data binding

CodingFoundations7 min read
Write a Spring MVC controller for a server-rendered sign-up form with fields name, email and age, using @ModelAttribute, Bean Validation and BindingResult, which redisplays the form with errors and redirects on success. Explain the post-redirect-get pattern.
DebuggingIntermediate7 min read
A security review finds that users can change their own role by adding role=ADMIN to a profile update form, because the controller binds @ModelAttribute User user directly to the JPA entity. Explain the mass assignment problem and the fixes in Spring MVC.
DesignAdvanced7 min read
A large internal back-office application has hundreds of server-rendered forms with complex nested objects, dynamic rows and multi-step wizards built with Spring MVC data binding. Maintenance is slow and bugs are common. How would you modernise form handling?
LeadershipPrincipal5 min read
Data binding frameworks made it easy to map HTTP input onto objects, and also caused serious vulnerabilities over the years (mass assignment, Spring4Shell, deserialisation flaws). What lessons would you draw for framework choices and secure defaults in your company?

Server-side templates: Thymeleaf, JSP and Vaadin

ConceptFoundations6 min read
Compare Thymeleaf, JSP and Vaadin for building web UIs in a Spring Boot application. Why does Spring Boot discourage JSP with executable jars, and how does Vaadin's model differ from template rendering?
ScenarioIntermediate7 min read
A Thymeleaf page listing 500 orders takes 3 seconds to render, and the logs show hundreds of SQL queries during view rendering. Explain what is happening and how you would fix it.
LeadershipAdvanced5 min read
Your company has 25 JSP-based internal applications on old Spring versions that must move to Spring Boot 3 and Jakarta EE namespaces. Teams ask whether to migrate JSP to Thymeleaf, to Vaadin, or rewrite as SPAs. How would you decide and plan?
LeadershipPrincipal6 min read
Web UI moved from JSP and server rendering to single-page apps, and now back toward server-driven approaches (htmx, Thymeleaf fragments, Vaadin, server components in JavaScript frameworks). How would you set the long-term UI technology strategy for a Java-heavy company?