Spring MVC
Learn about a few interview questions regarding Spring MVC.
We'll cover the following...
- What is Spring MVC?
- What are the advantages of using Spring MVC?
- What is the flow of request in the MVC architecture?
- What are the steps required to create a Spring MVC application?
- Is spring-mvc jar included in spring-core?
- What is the Front Controller Pattern?
- Describe the function of the DispatcherServlet.
- How is the Dispatcher servlet configured?
- How does the dispatcher servlet map a request to a controller method?
- What is a controller?
- What is the function of @Controller annotation?
- What is the difference between @Controller and @RestController annotations?
- What is the function of @RequestMapping annotation?
- When using @RequestMapping annotation, can multiple paths map to the same controller method?
- When using @RequestMapping annotation, can the same HTTP request be mapped to multiple controller methods?
- When using @RequestMapping annotation, can multiple HTTP request methods map to the same controller method?
- What is an ambiguous mapping error?
- What is the function of @ResponseBody annotation?
- What are the shortcut annotations for HTTP request methods?
- What is the isELIgnored attribute and what is its default value?
What is Spring MVC?
Spring MVC is the module of Spring that implements the front controller and MVC design pattern. It provides a decoupled approach to developing web applications.
In Spring MVC, the three components of the MVC architecture, the front controller, view resolver and model are not dependent on each other. All incoming requests are handled by the front controller which is called the DispatcherServlet.
What are the advantages of using Spring MVC?
- Spring MVC is based on interfaces which are independent of each other allowing separation of concerns.
- Because there is no explicit dependency between the interfaces, Spring MVC applications are easily testable.
- The view technology is customizable and switching between JSP, Velocity or Thymeleaf etc. can be done easily.
- Spring MVC supports RESTful web services.
What is the flow of request in the MVC architecture?
The dispatcher servlet is the front controller which receives all requests from the client. It has a mapping of all controllers and maps the incoming request to the appropriate controller.
The ...