Explain the purpose of the @RequestMapping annotation.

@RequestMapping is the core Spring MVC annotation for binding incoming HTTP requests to specific handler methods. It declares which URL patterns and HTTP methods a controller or method should respond to, so DispatcherServlet knows exactly where to route each request.

Key Points

Example

@RequestMapping("/api/users") on a class combined with @RequestMapping(method = RequestMethod.GET) on a method means that class handles all requests under /api/users, and that specific method only responds to GET requests there.

@RequestMapping("/api/users")
public class UserController {

    @RequestMapping(method = RequestMethod.GET)
    public List<User> listUsers() { ... }
}

Interview Tip

A concise interview answer is

@RequestMapping binds a URL pattern and HTTP method to a controller or handler method, which is how DispatcherServlet decides which code should run for a given request. It can be set at the class level for a shared base path and at the method level for specific routes, and the newer @GetMapping-style annotations are shorthand built on top of it.

Last updated: 16 July 2026

Previous question: How do servlets and listeners contribute to Spring MVC configuration?

Next question: How can you define method-level request mappings in a Spring MVC controller?

More Spring MVC (Optional) interview questions

All Spring MVC (Optional) questions