Spring Boot interview questions: Spring Web and REST APIs
Reviewed by Mark Dickie · Last updated
6 questions on this page you can answer and see marked on the spot. Go to the first one
Spring Boot is a layer over Spring Framework that auto-configures a web application with an embedded server, so a REST endpoint needs little setup. In a Spring Web interview, expect questions on how a controller method is matched to a request, how the JSON body becomes a Java object, and how exceptions turn into HTTP status codes. Interviewers usually want the annotation or class responsible for each step, and what the client receives when something fails.
Which Spring Web annotations come up most in Spring Boot REST interviews?
| Annotation or type | What it does in a REST API |
|---|---|
| @RestController | Marks a class whose method return values are written straight to the response body, combining @Controller and @ResponseBody |
| @GetMapping, @PostMapping | Shortcut forms of @RequestMapping that bind a method to one HTTP verb |
| @PathVariable | Binds a URI segment such as /orders/{id} to a method parameter |
| @RequestParam | Reads a query string value; it is required by default, so a missing one returns 400 |
| @RequestBody | Deserializes the JSON request body into a Java object through Jackson |
| @Valid | Runs Bean Validation on the bound object; a failure raises MethodArgumentNotValidException |
| ResponseEntity | Sets the status code, headers, and body together in one return value |
How does a request travel through Spring MVC?
- The embedded Tomcat server receives the request and passes it to DispatcherServlet.
- HandlerMapping finds the controller method whose path, verb, and headers match.
- HandlerAdapter resolves each argument, reading @RequestBody through an HttpMessageConverter.
- The return value is written back by a converter, Jackson for JSON.
- Any thrown exception goes to an @ExceptionHandler method, or to the default error handling if none matches.
How should a Spring Boot API report errors to clients?
Put shared handlers in a @RestControllerAdvice class and return ProblemDetail, which Spring Framework 6 models on RFC 9457. Setting spring.mvc.problemdetails.enabled=true makes Boot's default error responses use the same format. Be ready to explain why a 400 for a bad body differs from a 404 for a missing record, and where each one is raised.
Key facts
- Tarmac has 13 Spring Boot interview questions on this topic, 10 of them on this page, at difficulty 1–5 of 5.
- Tarmac tracked 811 job postings asking for Spring Boot in October 2026.
- Roles asking for Spring Boot advertise a median base salary of £75,000, across 159 job postings as of October 2026.
- Tarmac last reviewed these Spring Boot interview questions on 9 November 2026.
At a glance
| Questions | 10 shown · 13 in the bank |
|---|---|
| Difficulty | 1–5 of 5 |
| Formats | Multiple choice, Ordering, Multiple answer, Code output, True / false, Find the bug, Short answer, Fill in the blank, Flashcard |
What you'll review
- restcontrollers and request mapping
Practice questions
Try one before you open the answer. Pick an option and press Check; it's marked on the spot.
In Spring Boot (Spring Framework 6.x), which annotation is a convenience combination of @Controller and @ResponseBody, so every handler method's return value is written directly to the HTTP response body?#
Options
Show answer
@RestController is the Spring annotation that combines @Controller and @ResponseBody. Classes marked with it write each handler method's return value directly to the HTTP response body, typically as JSON, instead of resolving it as a view name.
@RestController is a composed annotation that is meta-annotated with @Controller and @ResponseBody. Marking a class with it means each handler method's return value is serialized into the response body (for example as JSON) rather than being resolved as a view name. @RequestBody binds an incoming request body to a method parameter, @Service marks a service-layer bean, and @RequestMapping maps URLs to handlers without changing how return values are written.
Put these steps in the order Spring MVC performs them when a client sends GET /api/users/42 to a @RestController method declared as @GetMapping("/api/users/{id}") public User getUser(@PathVariable Long id). Order them from first to last.#
Put these in order
Show answer
In Spring MVC, a GET request to a @RestController endpoint is handled by DispatcherServlet first, then matched to a handler method by handler mapping, then its arguments are resolved, the method runs, and its return value is serialized by an HttpMessageConverter. Each stage depends on the output of the one before it, so the order is fixed.
DispatcherServlet is the front controller and receives every request first. The handler mapping (RequestMappingHandlerMapping) then uses the HTTP method and path to select the getUser method. Before that method can be invoked, the handler adapter resolves its parameters, including extracting 42 from the {id} template variable for @PathVariable Long id. The method then executes and returns a User. Finally, because @RestController implies @ResponseBody, a message converter such as Jackson writes the object as JSON into the response body. Each step consumes the previous step's output, so the sequence is a strict total order.
Which of the following statements about @RestController and request mapping annotations in Spring Boot (Spring Framework 6.x) are true? Select all that apply.#
Options
Pick every one that applies.
Show answer
@RestController is a composite of @Controller and @ResponseBody, and @GetMapping is shorthand for @RequestMapping with the GET method. Class-level and method-level mapping paths are concatenated, so a class mapped to /api with a method mapped to /users serves /api/users. A String returned from a @RestController is written to the response body rather than resolved as a view.
@RestController is defined as @Controller plus @ResponseBody, so every handler method's return value is written directly to the response body. @GetMapping is a specialised form of @RequestMapping that fixes the HTTP method to GET. Class-level and method-level mapping paths are concatenated, so a class mapped to /api with a method mapped to /users serves /api/users. The statement about a returned String being resolved as a view name is false, because the @ResponseBody semantics bypass view resolution. The statement about @PathVariable is false, because it binds URI template variables such as {id} in the path, while @RequestParam handles query parameters.
Given this Spring Boot controller, what is the response body (exact text) returned for an HTTP GET request to /api/users/42?#
@RestController
@RequestMapping("/api/users")
public class UserController {
@GetMapping("/{id}")
public String getUser(@PathVariable long id) {
return "user " + id;
}
@GetMapping
public String listUsers() {
return "all";
}
}Show answer
user 42
The class-level @RequestMapping("/api/users") is combined with the method-level @GetMapping("/{id}"), so the handler is mapped to the pattern /api/users/{id}. The request path /api/users/42 matches that pattern with id bound to 42 (a long). Because @RestController serializes the String return value directly as the body, the method returns "user " + 42, which is the text user 42. The listUsers method is mapped to /api/users alone and does not match this request.
In Spring MVC (Spring Boot 3.x), what does annotating a class with @RestController add compared to annotating it with @Controller alone?#
Options
Show answer
@RestController combines @Controller and @ResponseBody. Because of that, each handler method's return value is serialized by an HttpMessageConverter, such as Jackson for JSON, and written straight to the response body rather than being resolved as a view name.
@RestController is a meta-annotation that is itself annotated with @Controller and @ResponseBody. The @ResponseBody part tells Spring MVC to pass each handler method's return value through an HttpMessageConverter (for example, Jackson for JSON) and write it to the response body, instead of resolving it as a view name. The bean scope stays singleton by default, component scanning is governed by @SpringBootApplication or @ComponentScan, and request mappings are only set by annotations such as @GetMapping or @RequestMapping, so none of the other options describe what the annotation adds.
In Spring MVC / Spring Boot, a controller handler method annotated only with @RequestMapping("/items") (no method attribute) handles only GET requests. True or false?#
Options
Show answer
False. A @RequestMapping handler with no method attribute matches all HTTP methods, not only GET. You restrict the verb by setting method explicitly or by using a shortcut such as @GetMapping, which sets the method for you.
The statement is false. When the method attribute of @RequestMapping is omitted, the mapping matches every HTTP method (GET, POST, PUT, DELETE, and so on) for the given path. Restricting a handler to a specific verb requires setting method explicitly, or using a shortcut annotation such as @GetMapping, which sets the method implicitly. The path is only one part of the match; the HTTP method is not defaulted to GET.
A developer expects GET /api/orders/42 to return the order with id 42, but every call fails at request time with a 500 error and the service method is never reached. Which option identifies the bug in this Spring Boot controller?#
@RestController
@RequestMapping("/api/orders")
public class OrderController {
@GetMapping("/{orderId}")
public Order getOrder(@PathVariable Long id) {
return orderService.findById(id);
}
}Options
Show answer
The @PathVariable on id has no name that matches the {orderId} template variable, so Spring cannot bind the path variable and the request fails before the method runs.
The method-level mapping declares the template variable orderId, but @PathVariable on the parameter id has no explicit name, so Spring looks for a path variable called id. That variable does not exist in the template, so argument resolution throws a missing-path-variable exception and the request ends with a server error before orderService.findById is invoked. The fix is @PathVariable("orderId") Long id (or renaming the parameter to orderId). The other options are wrong: a @RestController can return a plain object, class-level and method-level mappings combine normally, and @PathVariable is fully supported in REST controllers.
In a Spring Boot 3 application (Spring MVC with the default PathPatternParser), a @RestController declares two handler methods: @GetMapping("/users/{id}") and @GetMapping("/users/me"). A GET request to /users/me is dispatched to which handler method, and what rule determines this when more than one pattern matches the request path? Answer in 2 to 4 sentences, and do not depend on the order in which the methods are declared in the class.#
Show answer
The handler mapped to /users/me receives the request. When several patterns match a path, Spring MVC ranks them by specificity, and a pattern whose segments are literal text (such as me) is more specific than one that uses a path variable (such as {id}), so the most specific match wins regardless of declaration order.
Both patterns match the request path /users/me, so the dispatcher must choose one. Spring MVC's pattern comparator (PathPattern.SPECIFICITY_COMPARATOR in Spring 5.3 and later, which is the default in Spring Boot 3) prefers patterns with more literal characters and fewer captured variables, so the literal segment 'me' outranks the variable segment '{id}'. The handler for /users/me is therefore selected, and the method declaration order in the class has no effect on this choice.
In Spring MVC, @RestController is a composed annotation of @Controller and _____. The consumes attribute of a request mapping is matched against the request's _____ header, while the produces attribute is matched against the request's _____ header.#
Show answer
In Spring MVC, @RestController is a composed annotation of @Controller and @ResponseBody. The consumes attribute of a request mapping is matched against the request's Content-Type header, while the produces attribute is matched against the request's Accept header.
@RestController is meta-annotated with @Controller and @ResponseBody, so every handler's return value is written directly to the response body instead of being resolved as a view name. For request mapping, consumes restricts a handler to requests whose Content-Type header matches the declared media types, and produces restricts it based on what the client's Accept header permits. These two headers are the ones Spring compares against those attributes, so the blanks are ResponseBody, Content-Type and Accept respectively.
In Spring Framework 6.x / Spring Boot 3.x (default configuration, no custom PathMatchConfigurer), a controller method is mapped with @GetMapping("/users"). What happens when a client sends GET /users/ (with a trailing slash), and what is the default setting responsible for this?#
Show answer
The request is NOT matched by that handler and, by default, results in 404 Not Found. This is because trailing slash matching was disabled by default in Spring Framework 6.0 (PathMatchConfigurer's useTrailingSlashMatch defaults to false), so /users/ no longer matches a /users pattern. It can be re-enabled with PathMatchConfigurer.setUseTrailingSlashMatch(true), or the trailing-slash form can be mapped explicitly.
Before Spring Framework 6.0, trailing slash matching was on by default, so a mapping to /users also matched /users/. Spring 6.0 turned this off by default as part of moving toward PathPatternParser and away from suffix/trailing matching, which is why the same controller behaves differently after upgrading to Spring Boot 3. The card asks for the observable behavior plus the configuration default that causes it, and the back gives both, so the answer is fully determined by the default setting of the current major version.
Related interview questions
Job market
See spring-boot salaries and hiring demand from live job postings.
The other 3 questions
This page shows 10 and marks what you pick. That's as far as a page can go. A free account opens the other 3 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.
Free · the whole bank · 100 answers per 30 days, each marked with written feedback