Top Twenty Saltation Mvc Interview Questions Too Answers For Ii To V Years Experienced Coffee Programmers
The Spring MVC framework is ane of the most pop Java frameworks for developing web applications. If you lot bring been working inward Java as well as the developing web-based application as well as so at that topographic point is a practiced direct a opportunity that you lot bring already used Spring MVC inward your project. In terminal decade, it has acquire out the defacto framework for developing Java web application. Spring MVC is based on classic MVC (Model-View-Controller) pattern pattern but it is much to a greater extent than than that. It leverages, Spring framework's forcefulness inward damage of dependency injection as well as Inversion of control as well as promotes loosely coupled architecture, similar to the Spring framework itself. Because of its immense popularity as well as usefulness, most of the Java evolution job requires a good knowledge of Spring as well as Spring MVC.
There is a lot of demand for practiced Java developer with good knowledge and experience inward Spring as well as Spring MVC. One way to prepare yourself for such task interviews is to expect for practiced interview questions.
These questions non solely assistance you lot to prepare good for interviews but likewise assistance you lot to empathise the cardinal concepts improve as well as encourage you lot to acquire to a greater extent than past times exploring as well as that's why I am ever in search of practiced Spring MVC Interview questions.
Recently I was preparing for Spring Core Professional Certification when I come upwardly across some Spring certification guides from Pivotal. These guides contain some interesting questions on Spring MVC.
Even though these questions are provided only to give you lot an thought nearly the syllabus of Spring certification, I truly institute many of such questions bring already been asked to myself as well as friends inward diverse Spring task interviews.
On asking to a span of my friends, I thought to part answers to these questions here. So, if you lot are preparing for either Spring Certification or Java Web Developer interview, you lot volition discovery this listing of Spring MVC Interview Questions real useful for your preparation.
1. MVC is an abbreviation for a pattern pattern. What does it correspond as well as what is the idea behind it? (answer)
Answer - MVC is an abbreviation for Model-View-Controller pattern pattern. This pattern is based upon the separation-of-concerns design principle which promotes handling different functionality at different layer as well as loose coupling betwixt layers.
In MVC pattern, Model contains the information which is rendered past times View as well as Controler assistance inward asking processing as well as routing.
Neither Model knows about View, nor View is subject upon Model, which agency the same model tin survive rendered past times dissimilar views e.g. JSP, FreeMarker or it tin survive fifty-fifty survive written every bit JSON or XML inward instance of RESTful Web Services. You tin acquire to a greater extent than nearly MVC inward my favorite course of didactics Spring Framework 5: Beginner to Guru. If you lot are serious nearly Spring, this is the course of didactics you lot should look.
2. Do you lot demand spring-mvc.jar inward your classpath or is it component of spring-core? (answer)
The spring-mvc.jar is non component of spring-core, which agency if you lot desire to work Spring MVC framework inward your Java project, you lot must include spring-mvc.jar inward your application's classpath. In Java spider web application, spring-mvc.jar is unremarkably placed within /WEB-INF/lib folder.
3. What is the DispatcherServlet as well as what is it used for? (answer)
The DispatcherServlet is an implementation of Front Controller pattern pattern which handles all incoming spider web asking to a Spring MVC application. Influenza A virus subtype H5N1 Front Controller pattern (see Enterprise application pattern pattern) is a mutual pattern inward spider web applications whose task is to have all asking as well as road it to dissimilar components of application for actual processing.
In instance of Spring MVC, DispatcherServlet road spider web requests to Spring MVC controllers.
In Spring MVC, DispatcherServlet is used for finding the right Controler to procedure a request, which it does alongside the assistance of handler mapping e.g. @RequestMapping annotation.
It is likewise responsible for delegating logical thought cry to ViewResolver as well as and so sending the rendered response to the client.
4. Is the DispatcherServlet instantiated via an application context? (answer)
No, DispatcherServlet is instantiated past times Servlet containers like Tomcat or Jetty. You must define DispatcherServlet into the web.xml file every bit shown below.
You tin come across that load-on-startup tag is 1 which agency DispatcherServlet is instantiated when you lot deploy Spring MVC application to Tomcat or whatever other Servlet container. During instantiation, it looks for a file servlet-name-context.xml as well as and so initializes beans defined inward this file.
5. What is the root application context inward Spring MVC? How is it loaded? (answer)
In Spring MVC, the context loaded using ContextLoaderListener is called the "root" application context which belongs to the whole application spell the ane initialized using DispatcherServlet is truly specific to that servlet.
Technically, Spring MVC allows multiple DispatcherServlet in a Spring MVC spider web application as well as so multiple such contexts each specific for respective servlet but having same root context may exist. You tin farther check answer)
The @Controller is a Spring MVC musical note to define Controller but in reality, it's only a stereotype annotation. You tin fifty-fifty do a controller without @Controller past times annotating the Spring MVC Controller classes using @Component annotation. The existent task of asking mapping to handler method is done using @RequestMapping annotation.
7. What is the ContextLoaderListener as well as what does it do? (answer)
The ContextLoaderListener is a listener which helps to bootstrap Spring MVC. As the name suggests it loads as well as do ApplicationContext, so you lot don't bring to write explicit code to do do it.
The application context is where Spring edible bean leaves. For a Web application, at that topographic point is is a subclass called WebAppliationContext.
The ContextLoaderListener likewise necktie the lifecycle of the ApplicationContext to the lifecycle of the ServletContext. You tin acquire the ServletContext from WebApplicationContext using getServletContext() method.
8. What are you lot going to do inward the web.xml? Where do you lot house it?
The ContextLoaderListener is configured inward web.xml every bit listener as well as you lot position that within a tag every bit shwon below:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
When the Spring MVC web application is deployed, Servlet container created an instance of ContextLoaderListener course of didactics which loads the Spring's WebApplicationContext. You tin likewise see Spring MVC For Beginners to acquire to a greater extent than nearly ContextLoaderListener as well as WebApplicationContext as well as their role inward Spring MVC.
9. How is an incoming asking mapped to a controller as well as mapped to a method? (answer)
Sometimes this query is likewise asked How does DispatcherServlet knows which Controller should procedure the request? Well, the answer lies in something called handler mappings.
Spring uses handler mappings to associate controllers alongside requests, 2 of the commonly used handler mappings are BeanNameUrlHandlerMapping as well as SimpleUrlHandlerMapping.
In BeanNameUrlHandlerMapping, when the asking url matches the cry of the bean, the course of didactics inward the edible bean Definition is the controller that volition handgrip the request.
On the other hand, In SimpleUrlHandlerMapping, the mapping is to a greater extent than explicit. You tin specify the number of URLs and each URL tin survive explicitly associated alongside a controller.
Btw, if you lot are using annotations to configure Spring MVC, which you lot should as well as so @RequestMapping annotations is used to map an incoming request to a controller and a handler method.
You tin likewise configure @RequestMapping musical note past times URI Path, past times query parameters, past times HTTP methods of a request and past times HTTP headers introduce inward the request.
10. What is the @RequestParam used for? (answer)
The @RequestParam is a Spring MVC musical note which is used to extract asking parameter or query parameters from URL inward Controller's handler method every bit shown below:
public String personDetail(@RequestParam("id") long id){
....
homecoming "personDetails";
}
The @RequestParam musical note likewise supports information type conversion e.g. you lot tin come across hither a String is converted to long automatically but it tin likewise number inward an exception if query parameter is non introduce or inward instance of type mismatch. You tin likewise brand the parameter optional past times using requried=false e.g. @RequestParam(value="id", required=false )
11. What are the differences betwixt @RequestParam as well as @PathVariable? (answer)
Even though both @RequestParam as well as @PathVariable annotations are used to extract some information from URL, at that topographic point is a key divergence betwixt them.
The @RequestParam is used to extract query parameters e.g. anything after "?" inward URL spell @PathVariable is used to extract the part of the URI itself. For example, if the given URL is http://localhost:8080/SpringMVC/books/3232233/?format=json
Then you lot tin access the query parameter "format" using @RequestParam musical note as well as /books/{id} using @PathVariable, which volition give you lot 3232233.
Here is some other instance of @PathVariable,
@RequestMapping("/persons/{id}" )
public String personDetail (@PathVariable ("id" ) long id) {...}
This code tin extract somebody id=123 from /persons/123. It is especially used inward RESTful Web Services because their id is unremarkably component of URI or URL path.
12. What are some of the valid homecoming types of a controller method? (answer)
There are many homecoming types are available for a controller method inward Spring MVC which is annotated past times @RequestMapping within the controller. Some of the pop ones are:
You tin come across the sum listing of valid homecoming types for a Spring MVC controller here. http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-ann-return-types
Every homecoming type has its specific use. For example, if you lot are using String as well as so it agency Controller only homecoming View Name as well as this thought cry will resolve by ViewResolver.
If you lot don't desire to homecoming whatever thought cry lift homecoming type void. If you lot desire to laid thought cry every bit good every bit desire to mail some object work ModelAndView every bit a homecoming type.
13. What is a View as well as what's the thought behind supporting dissimilar types of View? (answer)
Influenza A virus subtype H5N1 View is an interface inward Spring MVC application whose implementations are responsible for rendering context and exposing the model. Influenza A virus subtype H5N1 unmarried thought exposes multiple model attributes. Views inward Spring MVC tin survive beans also.
They are probable to survive instantiated every bit beans past times a ViewResolver. As this interface is stateless, thought implementations should survive thread-safe. past times using ViewResolver, a logical cry of thought tin survive resolved into dissimilar types of View implementation e.g. JstlView for displaying JSP or other thought implementations for FreeMarker as well as Velocity.
If you lot are novel to Spring MVC as well as non familiar alongside these basic classes, as well as so I propose you lot acquire Spring past times joining ane of the free Spring courses I bring shared earlier.
14. How is the right View chosen when it comes to the rendering phase? (answer)
The right View is chosen past times ViewResolver inward Spring MVC. When Controller returns a logical thought cry to DispatcherServlet, it consults to ViewResolver to discovery the right View.
The ViewResolver depending upon its implementation resolves the logical thought into a physical resources e.g. a JSP page or a FreeMarker template.
For example, InternalResourceViewResolver is a default thought resolvers which converts logical thought cry e.g. "hello" to "/WEB-INF/hello.jsp" using prefix as well as suffix.
15. What is the Model? (answer)
Model is ane time again a reference to encapsulate information or output for rendering. Model is ever created as well as passed to the thought inward Spring MVC. If a mapped controller method has Model every bit a method parameter, as well as so a model instance is automatically injected past times Spring framework to that method.
Any attributes assault the injected model are preserved as well as passed to the View. Here is an instance of using Model inward Spring MVC:
public String personDetail(Model model) {
...
model.addAttribute("name", "Joe");
...
}
16. Why do you lot bring access to the model inward your View? Where does it come upwardly from? (answer)
You demand to bring access tot he model inward your View to homecoming the output. It's the model which contains the information to survive rendered. The Model comes with the Controller, which process their client asking as well as encapsulate the output into a Model object.
17. What is the purpose of the session scope? (answer)
The purpose of the session range is to do an instance of the edible bean for an HTTP Session. This agency the same bean tin serve multiple requests if it is scoped inward session. You tin define the scope of a Spring edible bean using range attribute or @Scope annotation in Spring MVC application.
18. What is the default range inward the spider web context? (answer)
The singleton range is the default range for a Spring edible bean fifty-fifty inward the spider web context. The other 3 Web context-aware scopes are a request, session, as well as global-session, which are solely available inward a spider web application aware ApplicationContext object. See Spring Master Class - Beginner to Expert to acquire to a greater extent than nearly ApplicationContext inward Spring.
19. Why are controllers testable artifacts? (answer)
In Spring MVC Controllers are testable artifacts because they are non direct coupled alongside whatever View technology. They only homecoming a logical View name, which tin survive easily tested.
20. What does the InternalResourceViewResolver do? (answer)
In Spring MVC, Influenza A virus subtype H5N1 ViewResolveer returns View to handgrip to output rendering based on the Logical View Name (provided past times the controller) as well as locale. This way controller is non coupled to specific thought engineering e.g. JSP or FreeMarker it solely returns the logical thought name.
InternalResourceViewResolver is the default View resolver configured inward Spring MVC as well as DispatcherServlet uses it to discovery the right view. InternalResourceViewResolver is used to homecoming JSPs (JstlView).
It Configures prefix as well as suffix to logical thought cry which as well as so results inward a path to specific JSP every bit shown below:
<bean class= "org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name= "prefix" value= "/WEB-INF/" />
<property cry ="suffix" value =".jsp" />
</bean>
So if Controller returns "hello" every bit logical thought name, the InternalViewResolver volition homecoming /WEB-INF/hello.jsp as well as DispatcherServlet will forrad the request to this JSP page for rendering.
That's all nearly some of the frequently asked Spring MVC Interview Questions. If you lot know answers to these questions agency you lot bring practiced cognition of Spring MVC framework, its different components e.g. DispatcherServlet, handler mappings, Controllers, Views as well as Model as well as tin explicate to anyone.
Sometime, you lot may acquire questions from Spring marrow as well as Spring safety every bit well, therefore it's likewise advisable to prepare for them. You tin discovery some Spring Security Interview query hither as well as Some Core Spring questions here.
Further Reading
Spring Framework 5: Beginner to Guru
Spring Master Class - Beginner to Expert
Spring Framework Interview Guide - 200+ Questions & Answers
Other Spring related articles you lot may similar to explore this blog
Thanks for reading this article. If you lot similar these questions as well as my answers as well as explanations as well as so delight part alongside your friends as well as colleagues, it does brand a difference. If you lot bring whatever questions which are non answered inward this list, experience gratuitous to drib a comment as well as I'll elbow grease my best to discovery an respond for you.
P.S. - If you lot desire to acquire how to prepare RESTful Web Services using Spring Framework, banking concern check out Eugen Paraschiv's REST alongside Spring course. He has lately launched the certification version of the course, which is sum of exercises as well as examples to farther cement the existent globe concepts you lot volition acquire from the course.
There is a lot of demand for practiced Java developer with good knowledge and experience inward Spring as well as Spring MVC. One way to prepare yourself for such task interviews is to expect for practiced interview questions.
These questions non solely assistance you lot to prepare good for interviews but likewise assistance you lot to empathise the cardinal concepts improve as well as encourage you lot to acquire to a greater extent than past times exploring as well as that's why I am ever in search of practiced Spring MVC Interview questions.
Recently I was preparing for Spring Core Professional Certification when I come upwardly across some Spring certification guides from Pivotal. These guides contain some interesting questions on Spring MVC.
Even though these questions are provided only to give you lot an thought nearly the syllabus of Spring certification, I truly institute many of such questions bring already been asked to myself as well as friends inward diverse Spring task interviews.
On asking to a span of my friends, I thought to part answers to these questions here. So, if you lot are preparing for either Spring Certification or Java Web Developer interview, you lot volition discovery this listing of Spring MVC Interview Questions real useful for your preparation.
20 Spring MVC Interview Questions for Java Programmers
Without farther Ado, hither is my listing of some of the often asked Spring MVC questions from Java Interviews, especially from the spider web evolution positions.1. MVC is an abbreviation for a pattern pattern. What does it correspond as well as what is the idea behind it? (answer)
Answer - MVC is an abbreviation for Model-View-Controller pattern pattern. This pattern is based upon the separation-of-concerns design principle which promotes handling different functionality at different layer as well as loose coupling betwixt layers.
In MVC pattern, Model contains the information which is rendered past times View as well as Controler assistance inward asking processing as well as routing.
Neither Model knows about View, nor View is subject upon Model, which agency the same model tin survive rendered past times dissimilar views e.g. JSP, FreeMarker or it tin survive fifty-fifty survive written every bit JSON or XML inward instance of RESTful Web Services. You tin acquire to a greater extent than nearly MVC inward my favorite course of didactics Spring Framework 5: Beginner to Guru. If you lot are serious nearly Spring, this is the course of didactics you lot should look.
2. Do you lot demand spring-mvc.jar inward your classpath or is it component of spring-core? (answer)
The spring-mvc.jar is non component of spring-core, which agency if you lot desire to work Spring MVC framework inward your Java project, you lot must include spring-mvc.jar inward your application's classpath. In Java spider web application, spring-mvc.jar is unremarkably placed within /WEB-INF/lib folder.
3. What is the DispatcherServlet as well as what is it used for? (answer)
The DispatcherServlet is an implementation of Front Controller pattern pattern which handles all incoming spider web asking to a Spring MVC application. Influenza A virus subtype H5N1 Front Controller pattern (see Enterprise application pattern pattern) is a mutual pattern inward spider web applications whose task is to have all asking as well as road it to dissimilar components of application for actual processing.
In instance of Spring MVC, DispatcherServlet road spider web requests to Spring MVC controllers.
In Spring MVC, DispatcherServlet is used for finding the right Controler to procedure a request, which it does alongside the assistance of handler mapping e.g. @RequestMapping annotation.
It is likewise responsible for delegating logical thought cry to ViewResolver as well as and so sending the rendered response to the client.
4. Is the DispatcherServlet instantiated via an application context? (answer)
No, DispatcherServlet is instantiated past times Servlet containers like Tomcat or Jetty. You must define DispatcherServlet into the web.xml file every bit shown below.
You tin come across that load-on-startup tag is 1 which agency DispatcherServlet is instantiated when you lot deploy Spring MVC application to Tomcat or whatever other Servlet container. During instantiation, it looks for a file servlet-name-context.xml as well as and so initializes beans defined inward this file.
5. What is the root application context inward Spring MVC? How is it loaded? (answer)
In Spring MVC, the context loaded using ContextLoaderListener is called the "root" application context which belongs to the whole application spell the ane initialized using DispatcherServlet is truly specific to that servlet.
Technically, Spring MVC allows multiple DispatcherServlet in a Spring MVC spider web application as well as so multiple such contexts each specific for respective servlet but having same root context may exist. You tin farther check answer)
The @Controller is a Spring MVC musical note to define Controller but in reality, it's only a stereotype annotation. You tin fifty-fifty do a controller without @Controller past times annotating the Spring MVC Controller classes using @Component annotation. The existent task of asking mapping to handler method is done using @RequestMapping annotation.
7. What is the ContextLoaderListener as well as what does it do? (answer)
The ContextLoaderListener is a listener which helps to bootstrap Spring MVC. As the name suggests it loads as well as do ApplicationContext, so you lot don't bring to write explicit code to do do it.
The application context is where Spring edible bean leaves. For a Web application, at that topographic point is is a subclass called WebAppliationContext.
The ContextLoaderListener likewise necktie the lifecycle of the ApplicationContext to the lifecycle of the ServletContext. You tin acquire the ServletContext from WebApplicationContext using getServletContext() method.
8. What are you lot going to do inward the web.xml? Where do you lot house it?
The ContextLoaderListener is configured inward web.xml every bit listener as well as you lot position that within a tag every bit shwon below:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
When the Spring MVC web application is deployed, Servlet container created an instance of ContextLoaderListener course of didactics which loads the Spring's WebApplicationContext. You tin likewise see Spring MVC For Beginners to acquire to a greater extent than nearly ContextLoaderListener as well as WebApplicationContext as well as their role inward Spring MVC.
9. How is an incoming asking mapped to a controller as well as mapped to a method? (answer)
Sometimes this query is likewise asked How does DispatcherServlet knows which Controller should procedure the request? Well, the answer lies in something called handler mappings.
Spring uses handler mappings to associate controllers alongside requests, 2 of the commonly used handler mappings are BeanNameUrlHandlerMapping as well as SimpleUrlHandlerMapping.
In BeanNameUrlHandlerMapping, when the asking url matches the cry of the bean, the course of didactics inward the edible bean Definition is the controller that volition handgrip the request.
On the other hand, In SimpleUrlHandlerMapping, the mapping is to a greater extent than explicit. You tin specify the number of URLs and each URL tin survive explicitly associated alongside a controller.
Btw, if you lot are using annotations to configure Spring MVC, which you lot should as well as so @RequestMapping annotations is used to map an incoming request to a controller and a handler method.
You tin likewise configure @RequestMapping musical note past times URI Path, past times query parameters, past times HTTP methods of a request and past times HTTP headers introduce inward the request.
10. What is the @RequestParam used for? (answer)
The @RequestParam is a Spring MVC musical note which is used to extract asking parameter or query parameters from URL inward Controller's handler method every bit shown below:
public String personDetail(@RequestParam("id") long id){
....
homecoming "personDetails";
}
The @RequestParam musical note likewise supports information type conversion e.g. you lot tin come across hither a String is converted to long automatically but it tin likewise number inward an exception if query parameter is non introduce or inward instance of type mismatch. You tin likewise brand the parameter optional past times using requried=false e.g. @RequestParam(value="id", required=false )
11. What are the differences betwixt @RequestParam as well as @PathVariable? (answer)
Even though both @RequestParam as well as @PathVariable annotations are used to extract some information from URL, at that topographic point is a key divergence betwixt them.
The @RequestParam is used to extract query parameters e.g. anything after "?" inward URL spell @PathVariable is used to extract the part of the URI itself. For example, if the given URL is http://localhost:8080/SpringMVC/books/3232233/?format=json
Then you lot tin access the query parameter "format" using @RequestParam musical note as well as /books/{id} using @PathVariable, which volition give you lot 3232233.
Here is some other instance of @PathVariable,
@RequestMapping("/persons/{id}" )
public String personDetail (@PathVariable ("id" ) long id) {...}
This code tin extract somebody id=123 from /persons/123. It is especially used inward RESTful Web Services because their id is unremarkably component of URI or URL path.
12. What are some of the valid homecoming types of a controller method? (answer)
There are many homecoming types are available for a controller method inward Spring MVC which is annotated past times @RequestMapping within the controller. Some of the pop ones are:
- String
- void
- View
- ModelAndView (Class)
- Model (Interface)
- Map
- HttpEntity<?> or ResponseEntity<?>
- HttpHeaders
You tin come across the sum listing of valid homecoming types for a Spring MVC controller here. http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-ann-return-types
Every homecoming type has its specific use. For example, if you lot are using String as well as so it agency Controller only homecoming View Name as well as this thought cry will resolve by ViewResolver.
If you lot don't desire to homecoming whatever thought cry lift homecoming type void. If you lot desire to laid thought cry every bit good every bit desire to mail some object work ModelAndView every bit a homecoming type.
13. What is a View as well as what's the thought behind supporting dissimilar types of View? (answer)
Influenza A virus subtype H5N1 View is an interface inward Spring MVC application whose implementations are responsible for rendering context and exposing the model. Influenza A virus subtype H5N1 unmarried thought exposes multiple model attributes. Views inward Spring MVC tin survive beans also.
They are probable to survive instantiated every bit beans past times a ViewResolver. As this interface is stateless, thought implementations should survive thread-safe. past times using ViewResolver, a logical cry of thought tin survive resolved into dissimilar types of View implementation e.g. JstlView for displaying JSP or other thought implementations for FreeMarker as well as Velocity.
If you lot are novel to Spring MVC as well as non familiar alongside these basic classes, as well as so I propose you lot acquire Spring past times joining ane of the free Spring courses I bring shared earlier.
14. How is the right View chosen when it comes to the rendering phase? (answer)
The right View is chosen past times ViewResolver inward Spring MVC. When Controller returns a logical thought cry to DispatcherServlet, it consults to ViewResolver to discovery the right View.
The ViewResolver depending upon its implementation resolves the logical thought into a physical resources e.g. a JSP page or a FreeMarker template.
For example, InternalResourceViewResolver is a default thought resolvers which converts logical thought cry e.g. "hello" to "/WEB-INF/hello.jsp" using prefix as well as suffix.
15. What is the Model? (answer)
Model is ane time again a reference to encapsulate information or output for rendering. Model is ever created as well as passed to the thought inward Spring MVC. If a mapped controller method has Model every bit a method parameter, as well as so a model instance is automatically injected past times Spring framework to that method.
Any attributes assault the injected model are preserved as well as passed to the View. Here is an instance of using Model inward Spring MVC:
public String personDetail(Model model) {
...
model.addAttribute("name", "Joe");
...
}
16. Why do you lot bring access to the model inward your View? Where does it come upwardly from? (answer)
You demand to bring access tot he model inward your View to homecoming the output. It's the model which contains the information to survive rendered. The Model comes with the Controller, which process their client asking as well as encapsulate the output into a Model object.
17. What is the purpose of the session scope? (answer)
The purpose of the session range is to do an instance of the edible bean for an HTTP Session. This agency the same bean tin serve multiple requests if it is scoped inward session. You tin define the scope of a Spring edible bean using range attribute or @Scope annotation in Spring MVC application.
18. What is the default range inward the spider web context? (answer)
The singleton range is the default range for a Spring edible bean fifty-fifty inward the spider web context. The other 3 Web context-aware scopes are a request, session, as well as global-session, which are solely available inward a spider web application aware ApplicationContext object. See Spring Master Class - Beginner to Expert to acquire to a greater extent than nearly ApplicationContext inward Spring.
19. Why are controllers testable artifacts? (answer)
In Spring MVC Controllers are testable artifacts because they are non direct coupled alongside whatever View technology. They only homecoming a logical View name, which tin survive easily tested.
20. What does the InternalResourceViewResolver do? (answer)
In Spring MVC, Influenza A virus subtype H5N1 ViewResolveer returns View to handgrip to output rendering based on the Logical View Name (provided past times the controller) as well as locale. This way controller is non coupled to specific thought engineering e.g. JSP or FreeMarker it solely returns the logical thought name.
InternalResourceViewResolver is the default View resolver configured inward Spring MVC as well as DispatcherServlet uses it to discovery the right view. InternalResourceViewResolver is used to homecoming JSPs (JstlView).
It Configures prefix as well as suffix to logical thought cry which as well as so results inward a path to specific JSP every bit shown below:
<bean class= "org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name= "prefix" value= "/WEB-INF/" />
<property cry ="suffix" value =".jsp" />
</bean>
So if Controller returns "hello" every bit logical thought name, the InternalViewResolver volition homecoming /WEB-INF/hello.jsp as well as DispatcherServlet will forrad the request to this JSP page for rendering.
That's all nearly some of the frequently asked Spring MVC Interview Questions. If you lot know answers to these questions agency you lot bring practiced cognition of Spring MVC framework, its different components e.g. DispatcherServlet, handler mappings, Controllers, Views as well as Model as well as tin explicate to anyone.
Sometime, you lot may acquire questions from Spring marrow as well as Spring safety every bit well, therefore it's likewise advisable to prepare for them. You tin discovery some Spring Security Interview query hither as well as Some Core Spring questions here.
Further Reading
Spring Framework 5: Beginner to Guru
Spring Master Class - Beginner to Expert
Spring Framework Interview Guide - 200+ Questions & Answers
Other Spring related articles you lot may similar to explore this blog
- 3 ways to acquire Spring Framework improve (article)
- How Spring MVC plant internally? (answer)
- What is the work of DispatcherServlet inward Spring MVC? (answer)
- How to enable Spring safety inward Java application? (answer)
- Does Spring certification assistance inward Job as well as Career? (article)
- How to prepare for Spring Certification? (guide)
- 3 Best Practices Java Developers Can acquire from Spring (article)
- Difference between @Autowired as well as @Injection annotations inward Spring? (answer)
- 5 Spring as well as Hibernate online courses for Java developers (list)
- 5 Spring Boot courses for Java developers (courses)
- 5 courses to acquire Microservices alongside Spring Boot as well as Spring Cloud (courses)
Thanks for reading this article. If you lot similar these questions as well as my answers as well as explanations as well as so delight part alongside your friends as well as colleagues, it does brand a difference. If you lot bring whatever questions which are non answered inward this list, experience gratuitous to drib a comment as well as I'll elbow grease my best to discovery an respond for you.
P.S. - If you lot desire to acquire how to prepare RESTful Web Services using Spring Framework, banking concern check out Eugen Paraschiv's REST alongside Spring course. He has lately launched the certification version of the course, which is sum of exercises as well as examples to farther cement the existent globe concepts you lot volition acquire from the course.





Komentar
Posting Komentar