Top 50 Spring Web MVC Interview Questions & Answers

1) What is Spring Web MVC?
Answer:

Spring Web MVC is one module available in Spring Framework and it is used to develop web applications & distributed applications.

2) What do u mean by Spring MVC Framework?
Answer:

Spring MVC is one module in Spring Framework which is built on the Servlet API. It provides Model-View-Controller architecture that can be used to develop flexible web applications using Spring Framework.

3) Is Spring 5 compatible with older versions of Java?
Answer:

To build and run Spring 5 application, you will need minimum JDK 8 and

Java EE 7. Previous JDK and Java EE versions are not supported anymore.

4) What are the Design Patterns Used by Spring?
Answer:

Singleton Pattern : Singleton-scoped beans

Factory Pattern : Bean Factory classes

Prototype Pattern : Prototype-scoped beans

Adapter Pattern : Spring Web and Spring MVC

Proxy Pattern : Spring Aspect Oriented Programming support

Template Method Pattern : JdbcTemplate, HibernateTemplate, etc.

Front Controller : Spring MVC DispatcherServlet

Data Access Object : Spring DAO support

Model View Controller : Spring MVC

5) Explain Spring MVC Architecture.
Answer:


Spring MVC architecture is based on Model, View, and Controller.

The flow of the Spring Architecture goes in the following way:

1. The request is received by the dispatcher servlet.

2. Dispatcher servlet sends the request to the handler mapping which provides the response in terms of controller class name.

3. Now the request is sent to the Controller from the dispatcher servlet, hence the controller processes the request and returns the model view object as a response to the dispatcher servlet.

4. Again, the dispatcher servlet sends the request to view resolver to get the correct view page.

5. Lastly, the dispatcher servlet sends the model object received to the browser page to display the result.

The @Controller and @RequestMapping are the two main annotations that are used in Spring MVC flow.


cover image