Spring MVC Interview Questions and Answers
Spring MVC Interview Questions and Answers
Spring MVC Interview Questions and Answers
Home Core Java Spring Spring Boot Hibernate Struts 2 J2EE Web Services Hadoop Design Patterns Maven MongoDB
Dinesh
3,134 likes
Posted by Dinesh Rajput
Be the first of your fri
This tutorial has popular Spring MVC Interview Questions and answers. These have been written to help you prepare
for the interviews and quickly revise the concepts in general. Before reading these questions you can practice with
Spring MVC tutorial with Examples. There are following selected questions related to the Spring MVC.
LABELS
1. What is Spring MVC framework?
2. MVC is an abbreviation for a design pattern. What does it stand for and what is the idea behind it? About My Professiona
AJAX (4)
3. Do you need spring-mvc.jar in your classpath or is it part of spring-core? Ant (11)
4. What is the DispatcherServlet and what is it used for? cloud computing
collection (18)
5. Is the DispatcherServlet instantiated via an application context?
Core JAVA
6. What is the root application context? How is it loaded? Core Java Interview Q
Garbage Collection
7. What is the @Controller annotation used for? How can you create a controller without an annotation?
GitHub (3)
8. What is the ContextLoaderListener and what does it do? Gradle (3)
9. What are you going to do in the web.xml. Where do you place it? Hadoop (14)
Hibernate (14)
10. How is an incoming request mapped to a controller and mapped to a method? hibernate4
11. What is the @RequestParam used for? interview questions
Java (3)
12. What are the differences between @RequestParam and @PathVariable?
JavaMail (14)
13. What are some of the valid return types of a controller method? JAXB (4)
14. What is a View and what's the idea behind supporting different types of View? JDBC (1)
JSP (29)
15. How is the right View chosen when it comes to the rendering phase? JSTL (44)
16. What is the Model? Linux (2)
Logging (2)
17. Why do you have access to the model in your View? Where does it come from?
maven (12)
18. What is the purpose of the session scope? Microservices
migration (1)
19. What is the default scope in the web context?
mongodb (18)
20. Why are controllers testable artifacts? motivational
21. What does the InternalResourceViewResolver do? multithreading
REST (19)
22. What’s internal resource views? Security (1)
Servlet (26)
SOAP (9)
Spring 5 (1)
Popular Tutorials Spring Batch
Spring Batch3
Spring Tutorial Spring Boot
Spring HATEOAS
Spring MVC Web Tutorial
Spring Mobile
Spring Boot Tutorial Spring MVC
Spring Security Tutorial Spring MVC interview
Spring3.0 (90)
Spring AOP Tutorial
Spring4 (12)
Spring JDBC Tutorial SpringSecurity
String in Java
Spring HATEOAS
struts2 (49)
Microservices with Spring Boot thymeleaf (1)
REST Webservice UDDI (1)
WebService
Core Java WSDL (9)
Hibernate Tutorial
Spring Batch
http://www.dineshonjava.com/2017/02/spring-mvc-interview-questions-and-answers.html#5 1/7
2/15/2017 Spring MVC Interview Questions and Answers | Dinesh on Java
7 7 7
1. What is Spring MVC framework?
MENU
The Spring web MVC framework provides model-view-controller architecture and ready components that can be used
to develop flexible and loosely coupled web applications. The MVC pattern results in separating the different aspects ▼ 2017 (28)
February (15)
of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements.
January (13)
Read More about Spring MVC Framework.
► 2016 (60)
► 2015 (11)
2. MVC is an abbreviation for a design pattern. What does it stand for and what is the idea behind it?
► 2014 (89)
MVC is an abbreviation name for a J2EE design pattern and it stands for Model View Controller. According to MVC
► 2013 (352)
design pattern in J2EE application we have three layers of architecture as Controller, Model and Service layers. A
► 2012 (85)
Model View Controller pattern is made up of the following three parts:
ADS
Model - The lowest level of the pattern which is responsible for maintaining data.
View - This is responsible for displaying all or a portion of the data to the user.
Controller - Software Code that controls the interactions between the Model and View.
MVC is popular as it isolates the application logic from the user interface layer and supports separation of concerns.
Here the Controller receives all requests for the application and then works with the Model to prepare any data
needed by the View. The View then uses the data prepared by the Controller to generate a final presentable
response. Read more about MVC design pattern.
Spring-mvc.jar is not part of spring core because the Core Container consists of the spring-core, spring-beans,
spring-context, spring-context-support, and spring-expression (Spring Expression Language) modules.
DispatcherServlet is responsible for initialize the WebApplicationContext and it loads all configuration related to the
web components like controllers, view resolver, interceptors etc., It will be loaded and initialized by calling init()
method init() of DispatcherServlet will try to identify the Spring Configuration Document with naming conventions like
"servlet_name-servlet.xml" then all beans can be identify. Read more about DispatcherServlet in Spring MVC.
7. What is the @Controller annotation used for? How can you create a controller without an annotation?
In Spring MVC framework @Controller used for creating controllers for the web application. It is meta annotation of
@Component annotation to create the bean by spring container.
The @Controller annotation indicates that a particular class serves the role of a controller. Spring does not require
http://www.dineshonjava.com/2017/02/spring-mvc-interview-questions-and-answers.html#5 2/7
2/15/2017 Spring MVC Interview Questions and Answers | Dinesh on Java
you to extend any controller base class or reference the Servlet API. Read more about @Controller, @Repository
and @Service stereotype annotations.
9. What are you going to do in the web.xml. Where do you place it?
For Spring MVC application we have to do following entry in web.xml file which place under the WEB-INF folder.
1. <servlet>
2. <servlet-name>webapp1</servlet-name>
3. <servlet-class>
4. org.springframework.web.servlet.DispatcherServlet
5. </servlet-class>
6.
7. <!-- We require this configuration when we want to change the default
8. name / location of the servlet specific configuration files -->
9. <init-param>
10. <param-name>contextConfigLocation</param-name>
11. <param-value>/WEB-INF/app1-servlet.xml</param-value>
12. </init-param>
13. <load-on-startup>0</load-on-startup>
14. </servlet>
1. <!-- This is the root application context for whole web application. -->
2. <context-param>
3. <param-name>contextConfigLocation</param-name>
4. <param-value>/WEB-INF/rootApplicationContext.xml</param-value>
5. </context-param>
6. <listener>
7. <listener-class>
8. org.springframework.web.context.ContextLoaderListener
9. </listener-class>
10. </listener>
10. What is @RequestMapping? How is an incoming request mapped to a controller and mapped to a
method?
@RequestMapping can be applied to the controller class as well as methods. This annotation for mapping web
requests onto specific handler classes and/or handler methods. Read more about @RequestMapping annotation
in Spring MVC.
http://www.dineshonjava.com/2017/02/spring-mvc-interview-questions-and-answers.html#5 3/7
2/15/2017 Spring MVC Interview Questions and Answers | Dinesh on Java
1. @Target(value=PARAMETER)
2. @Retention(value=RUNTIME)
3. @Documented
4. public @interface RequestParam
defaultValue-It is String type attribute and the default value to use as a fallback when the request
parameter is not provided or has an empty value.
name-It is String type attribute and name of the request parameter to bind to.
required-It is boolean type attribute whether the parameter is required.
value- It is String type attribute and it is alias for name attribute.
@RequestParam: It is used to get the request parameters. @RequestParam automatically binds the request
parameters to the arguments of your handler method. It also provides auto type conversion for some standard type
like int, long, float, string, date etc.Read more about differences between @RequestParam and @PathVariable
annotation in Spring MVC.
13. What are some of the valid return types of a controller method?
There are many return types are available for Handler method which is annotated by @RequestMapping inside
controller like :
ModelAndView (Class)
Model (Interface)
Map
String
void
View
HttpEntity<?> or ResponseEntity<?>
HttpHeaders
14. What is a View and what's the idea behind supporting different types of View?
15. How is the right View chosen when it comes to the rendering phase?
View Resolvers
The DispatcherServlet delegates to a ViewResolver to obtain View implementation based on view name.
http://www.dineshonjava.com/2017/02/spring-mvc-interview-questions-and-answers.html#5 4/7
2/15/2017 Spring MVC Interview Questions and Answers | Dinesh on Java
The default ViewResolver treats the view name as a Web Application-relative file path – i.e. a JSP: /WEB-
INF/reward/list.jsp
Override this default by registering a ViewResolver bean with the DispatcherServlet
We will use InternalResourceViewResolver
Several other options available.
17. Why do you have access to the model in your View? Where does it come from?
In the Spring MVC model has data to be rendered front to the user so spring provide support to access the model in
the view layer. This model is passed by the controller to the dispatcher servlet and dispatcher server send it to the
respective view resolver for rendering model's data to the view and generate html page upfront to user.
The idea here is that you have a web application, and you have various objects that exist on a per-session basis,
such as maybe a user profile or a shopping cart. You’d like to make those available to some service bean, say,
without having to manually pull them off the session and pass them as method arguments every time.
http://www.dineshonjava.com/2017/02/spring-mvc-interview-questions-and-answers.html#5 5/7
2/15/2017 Spring MVC Interview Questions and Answers | Dinesh on Java
14. Spring MVC Tiles Plugin with Example
15. Spring MVC Interceptor with example
16. Spring MVC with MongoDB CRUD Example
17. Spring MVC Internationalization & Localization with Example
0 Comments dineshonjava
1 Login
Sort by Best
Recommend 4 ⤤ Share
ALSO ON DINESHONJAVA
Spring MVC Exception Handling Example | DOJ Serialization in Java | DOJ Software Consultant
Software Consultant 1 comment • 2 years ago•
1 comment • a year ago• manish thakur — If a class has a reference of another class, all
karthik veerababu chitrothu — Thanks the references must be Serializable otherwise serialization
process will not be performed. In such case, …
Hadoop Architecture | DOJ Software Consultant Essentials and Key Components of Spring Boot | DOJ
3 comments • 2 years ago• Software Consultant
raja — Hi DineshYou are providing awesome tutorials ,Not able 4 comments • 8 months ago•
to click from module 4 onwards ..links are missing i Dinesh Rajput — Thanks Vijay.
guess.http://www.dineshonjava.com/20...
Subscribe to: Post Comments (Atom)
POPULAR POSTS
Spring 3.0 MVC with Hibernate 3.0 CRUD Example
In this example show how to write a simple web based application with CRUD operation using Spring3 MVC Framwork with Hibernate3 using Annot...
http://www.dineshonjava.com/2017/02/spring-mvc-interview-questions-and-answers.html#5 6/7
2/15/2017 Spring MVC Interview Questions and Answers | Dinesh on Java
Core JAVA Tutorial Core JAVA a Baby Step to be a Best Java ian
Hello Friends, Now we will focused on the Core Java tutorial, it is really a baby step to be a good, better and best Java ian :) . ...
Spring Tutorial A Baby Step to Learn
In this series of spring tutorial, it’s provides many step by step examples and explanations on using Spring framework. The Spring framewo...
Spring Security Tutorial take a Baby step to be Secure
In this spring security tutorial we will discuss about some of the security tips about the Spring Framework. Spring Security is a powerful...
How does java Hashmap work internally
What is Hashing? Hashing in its simplest form, is a way to assigning a unique code for any variable/object after applying any formula/algor...
REST and SOAP Web Service Interview Questions
In this interview questions tutorial we will explain most asking interviews questions on the web services like SOAP, REST etc and its protoc...
NamedParameterJdbcTemplate in Spring with Example
The NamedParameterJdbcTemplate class helps you specify the named parameters inste a d of classic placeholder('?') argument. Named pa...
Hibernate Tutorial Hibernate 3 on Baby Steps
This hibernate tutorial provide step by step instructions on using Hibernate 3.0. Hibernate is popular open source object relational ma...
Spring Batch TutorialSpring Batch with Example
Hi In this spring batch tutorial I will discuss about one of the excellent feature of Spring Framework name Spring Batch. Spring Batch is a ...
Spring MVC Tutorial with Examples
Model view controller is a software architecture design pattern. It provides solution to layer an application by separating three concerns...
http://www.dineshonjava.com/2017/02/spring-mvc-interview-questions-and-answers.html#5 7/7