Quick revision
The short answer
Functional endpoints and annotated controllers run on the same DispatcherServlet, so mixing them costs nothing technically; the real cost is two sets of conventions, tests and review rules that every team has to learn and maintain. I would pick annotated controllers as the organisation's default, allow RouterFunction for clear cases such as small composed routes or route tables built in code, and revisit the decision if the ecosystem or tooling shifts.
What to remember
In this answer, we saw that annotated controllers and functional endpoints share the same DispatcherServlet machinery, so mixing them is free at runtime. The real cost is organisational: two conventions, two test patterns, two review checklists and uneven tool support, paid by every team for years. The sensible policy is one default, annotated controllers for most organisations, with functional routes allowed for clearly stated cases, and a planned review in case the ecosystem shifts.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Functional endpoints and annotated controllers run on the same DispatcherServlet, so mixing them costs nothing technically; the real cost is two sets of conventions, tests and review rules that every team has to learn and maintain. I would pick annotated controllers as the organisation's default, allow RouterFunction for clear cases such as small composed routes or route tables built in code, and revisit the decision if the ecosystem or tooling shifts.
Why this question is asked
When a framework offers two ways to do the same job, the choice stops being a technical question and becomes an organisational one. Nobody's service breaks because one team writes RouterFunction beans while another writes @GetMapping methods, but every new joiner, reviewer and shared library now has to understand both. Interviewers ask this at a senior level to see whether we can separate what is technically possible from what is cheap to support for years. In this answer, we will recap what the two styles are, see why they mix so easily, count the long-term cost of supporting both, and then walk through how we would make and document the decision.
1A Quick Recap of the Two Styles
An annotated controller is a class marked @RestController or @Controller whose methods carry mapping annotations such as @GetMapping("/orders/{id}"). Spring scans these annotations at startup and builds a table of routes. Parameters are filled by annotations too: @PathVariable, @RequestParam, @RequestBody.
A functional endpoint describes the same thing in plain Java code. A RouterFunction is an object that, given a request, decides which handler should serve it. A HandlerFunction is the handler itself: a function that takes a ServerRequest and returns a ServerResponse. Nothing is discovered by scanning; we build the routes ourselves and expose them as a bean.
Both snippets serve GET /orders/42 with the same JSON. The difference is where the routing knowledge lives: in annotations spread over methods, or in one piece of code we can read top to bottom, compose and test as a value.
2Why Mixing Them Is Technically Easy
Both styles plug into the same DispatcherServlet, the front controller that receives every request. DispatcherServlet asks a list of handler mappings who can serve the request. RequestMappingHandlerMapping knows the annotated controllers, and RouterFunctionMapping knows the RouterFunction beans. Whichever finds a match hands back a handler, and a matching handler adapter invokes it.
So filters, Spring Security, interceptors, message converters, exception handling and observability all apply to both styles. A single service can have an annotated OrderController and a functional route for /health/deep, and neither notices the other. This is the reason the decision is not about whether mixing works: it does. It is about whether we want to pay for two ways of doing one thing.
- Servlet filters and Spring Securitythe same for both styles
- DispatcherServletasks each handler mapping in order
- RequestMappingHandlerMappingfinds
@GetMappingmethods - RouterFunctionMappingfinds
RouterFunctionroutes - Handler adaptersinvoke a
HandlerMethodor aHandlerFunction - Message converters and exception resolversshared by both
6 layers, from the top down. Step through them one at a time.
Everything above and below the mappings is shared, which is why mixing is cheap at runtime.
3What Supporting Both Costs Over the Years
The cost shows up in people, not in CPU. Two styles mean two sets of conventions: how to name handler classes, where validation happens (annotations on @RequestBody parameters versus calling a validator inside a handler), how errors are mapped, and how routes are documented. Code review needs two checklists, and a reviewer fluent in one style misses problems in the other.
Tests split too. Annotated controllers are tested with @WebMvcTest and MockMvc, which every Spring developer already knows. Functional routes can also be tested through MockMvc, and recent Spring versions added direct builders for router functions (check your version), but the patterns, helpers and examples in our shared test libraries would have to exist twice.
Tooling follows the same pattern. OpenAPI generators, security scanners and IDE navigation work best with annotations, because they can read them statically. A functional route table is code that has to run before anything knows its routes, so generated documentation needs extra metadata. Hiring matters as well: almost every Spring developer has written annotated controllers; far fewer have maintained a large functional route table. Each of these costs is small on its own, but they are paid by every team, on every service, for as long as both styles exist.
4Where the Functional Style Earns Its Place
The functional style is not worse; it fits different problems. It shines when routes are small and composed: a handful of endpoints that share a filter, nested paths built from configuration, or routes registered conditionally from code, such as one route per enabled plugin. Because a RouterFunction is a value, we can build it in a loop, wrap it with filter() and test the routing in isolation without starting a web context.
Annotated controllers fit the common case: a resource with a dozen endpoints, validation on request bodies, and documentation generated from annotations. That is most of what a typical organisation builds.
| Situation | Better fit | Why |
|---|---|---|
| Typical CRUD or business API | Annotated controllers | known by everyone, best tool support |
| Routes generated from configuration | RouterFunction | routes are data built in code |
| Tiny service with three routes | Either; follow the default | no benefit worth a second convention |
| Shared library adding endpoints | RouterFunction | no component scanning needed |
Team already fluent in WebFlux.fn | Allowed by exception | only if reviewers can support it |
5Making and Recording the Decision
The decision I would take is to pick one default and allow the other only for clear cases. The default is annotated controllers, because it is what most of our developers, tests and tools already understand. RouterFunction is allowed where the routes are genuinely computed or composed, and the team writes one sentence in the service's design notes saying why.
To make the default real rather than a wiki page, the shared platform starter, the service template and the testing guide all show the annotated style. Code review accepts functional routes only with that stated reason. We do not force existing functional services to migrate, because rewriting working code to match a style guide rarely pays back. The rule applies to new code and to services that are being substantially rewritten anyway.
Finally, we put a review date on the decision, for example once a year or at each major Spring upgrade. If the ecosystem moves, for example if documentation tools, test support or hiring patterns start favouring the functional style, we revisit it with fresh evidence instead of defending the old choice out of habit.
6Follow-up questions
Can one service use both styles at the same time?
Yes. Both register handler mappings with the same DispatcherServlet, so a service can have annotated controllers and RouterFunction beans side by side, sharing filters, security and converters. The order of the mappings decides which wins if both define the same path, which is one more reason to keep overlapping routes out of a mixed service.
Is the functional style faster?
Not in any way that matters for a typical service. Both styles end up invoking a Java method after a route lookup, and the time is dominated by the database and network calls inside the handler. Performance is not a reason to pick either style; readability, tooling and team knowledge are.
What would make you change the default later?
Evidence that the cost balance has moved. For example, if most new hires arrive fluent in the functional style, if our documentation and testing tools support it as well as annotations, or if a large part of our services start needing computed routes. We would then trial it on a few services, measure review and onboarding effort, and update the default deliberately.
7Conclusion
In this answer, we saw that annotated controllers and functional endpoints share the same DispatcherServlet machinery, so mixing them is free at runtime. The real cost is organisational: two conventions, two test patterns, two review checklists and uneven tool support, paid by every team for years. The sensible policy is one default, annotated controllers for most organisations, with functional routes allowed for clearly stated cases, and a planned review in case the ecosystem shifts.
Open with
I'd start by saying that technically this is an easy question. RouterFunctionMapping and RequestMappingHandlerMapping both sit inside the same DispatcherServlet, so filters, security, converters and exception handling are shared, and one service can mix both styles without problems.
Then, if they want more
So the decision is really about the cost of supporting two ways of doing the same thing. That cost is people's time: two sets of conventions for validation, error handling and naming, two testing patterns, two review checklists, and tools like OpenAPI generators that read annotations more easily than route code.
Hiring matters too, because almost every Spring developer knows annotated controllers. The functional style is genuinely good when routes are small and composed, or computed from configuration, or contributed by a shared library without component scanning. So my decision would be one default, annotated controllers, built into the service template, the platform starter and the testing guide.
Functional routes are allowed when the team states a clear reason, like generated routes, and reviewers check that reason. I wouldn't force working functional services to migrate, because a style rewrite rarely pays back; the rule applies to new code and to services being rewritten anyway.
And I'd put a review date on the decision, say yearly or at each major Spring upgrade, so if the tooling or the skills in the market move towards the functional style, we change the default based on evidence rather than habit.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Spring Web MVC
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Spring MVC added functional endpoints (RouterFunction) alongside annotated controllers....": https://scrivio-interview-library.netlify.app/spring-boot/mvc-architecture/83c72118db/