Spring MVC architecture
38 questions in 10 subtopics.
DispatcherServlet
What is the front controller pattern and how does Spring Boot registerDispatcherServlet?Walk through what DispatcherServlet.doDispatch does for a request to a @RestController method.A request to /api/orders/ returns 404 after an upgrade to Spring Boot 3, while /api/orders works. What changed?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
What doHandlerMapping and HandlerAdapter do, and why are they separate?How does Spring choose between two mappings, GET /users/{id} and GET /users/me, for a request to /users/me?Startup fails with 'Ambiguous mapping. Cannot map method ... There is already ... bean method mapped'. What causes this and how do you find the conflict?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
Write aHandlerMethodArgumentResolver so that a controller parameter annotated @CurrentTenant Tenant tenant is filled from the X-Tenant header.How is a @RequestBody parameter turned into a Java object, and where can you change the process?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.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
What is the difference between a servlet Filter and aHandlerInterceptor? Give one use case for each.Register two filters so that a correlation id filter runs before Spring Security and a metrics filter runs after it. Show how ordering works.A HandlerInterceptor adds a response header in postHandle, but the header never appears for @RestController methods. Why?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
How does Spring MVC resolve a view when a@Controller method returns "orders/list", and how does this differ from a @RestController?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?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
Describe the full life of an HTTP request in a Spring Boot MVC application, from the socket to the response.What changes in the request lifecycle when a controller returnsDeferredResult or CompletableFuture?Your organisation has MVC services and WebFlux services. With virtual threads available, would you standardise on one stack for new services?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?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
Write aWebMvcConfigurer 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?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.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
Write a Spring MVC endpoint that returns a report generated in about 10 seconds without holding the servlet thread, using Callable orDeferredResult, and configure the async timeout and the executor. What does the client see on timeout?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?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
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.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.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?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
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?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.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?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?No question matches these choices.