Top 23 Spring MVC Framework Interview Questions Answers - Java JEE

Spring Interview Questions Answers 
Spring Interview Question is one of the first things Java programmer should prepare before appearing on any Java or Spring interview. With growing popularity of Spring framework in Java world, Interview questions on Spring are getting more important day by day. For those who don't know, Spring framework is one of the most popular Java programming framework, which not only provided dependency Injection and Inversion of Control but also provides useful API to Java programmers. Spring framework is divided into many different modules e.g. Spring MVC, Spring Integration, Spring Batch, Spring LDAP, Spring Security and several other modules. Based on your work experience, Interviewer can ask questions from core Spring or these modules. That's why, while preparing Spring interview question focus on Spring core, Spring Security, and Spring API, these are main areas from where interviewer ask questions.

If you have working experience in Spring based Java projects, you can easily answer most of these Spring questions asked in Java interview, but if you don't have any prior experience and just learning Spring, you need to not only prepare answers of these Spring questions but also some follow-up questions, which may stem from your answers.



Spring Interview Questions and Answers

Anyway let's see frequently asked questions on Spring framework on Java interviews :

1) What is spring framework? Why Java programmer should use Spring framework
Very common Spring interview question, Spring is a framework which helps Java programmer in development. Spring provides dependency Injection and IOC container, Spring MVC flow and several useful API for Java programmer.



2) What is default scope of bean in Spring framework ?
The default scope of a Spring bean is Singleton scope, you can read this article which explains about all possible scope of a spring bean : What is bean scope in Spring


3) Does Spring singleton beans are thread-safe ?
No, Spring singleton beans are not thread-safe. Singleton doesn't mean bean would be thread-safe.


4) What is dependency Injection?
Dependency Injection is one of the design pattern, which allows injecting dependency on Object, instead of object resolving the dependency.

5) What is Inversion of Control concept, how does Spring support IOC?

6) What is Spring MVC ? Can you explain How one request is processed ?

7) How to you create a controller in Spring ?


8) What is view Resolver pattern ? how it work in Spring MVC
Spring Framework Interview Question Answers | Spring MVC FAQView Resolver pattern is a J2EE pattern which allows a web application to dynamically choose it's view technology e.g. HTML, JSP, Tapestry, JSF, XSLT or any other view technology. In this pattern, View resolver holds mapping of different views, controller return name of the view, which is then passed to View Resolver for selecting an appropriate view. Spring MVC framework supplies inbuilt view resolver for selecting views.



9) What is Spring Security ?
Spring security is a project under spring framework umbrella, which provides support for security requirements of enterprise Java projects. Spring Security formerly known as aegis security provides out of box support for creating login screen, remember me cookie support, securing URL, authentication provider to authenticate the user from the database, LDAP and in memory, concurrent active session management support and much more. In order to use Spring security in a Spring MVC based project, you need to include spring-security.jar and configure it in application-Context-security.XML file, you can name it whatever you want, but make sure to supply this to ContextLoaderListener, which is responsible for creating Spring context and initializing dispatcher servlet. You can see Pro Spring Security by Carlo Scarioni to learn more about Spring Security.

Spring MVC Interview Questions Answers




10) How do you control concurrent Session on Java web application using Spring Security?
You can use Spring Security to control a number of active session in Java web application. Spring security framework provides this feature out of the box and when enabled , a user can only have one active session at a time. See this Spring Security example to learn more about How to control concurrent user session using Spring security


11) What types of dependency injection is supported by Spring Framework? When do you use Setter and Constructor Injection, pros and cons?
There are 2 types of dependency injection supported by Spring, constructor based injection, and setter-based injection. Both types have their own advantages and disadvantages, you should use Constructor injection when object's dependencies are not optional and they must be initialized with their dependencies. Also use constructor injection if the order of initialization or dependency matters because in Setter based injection you cannot impose any order. Use setter injection when dependencies are optional. See the difference between setter and constructor injection in Spring for more detailed answer.


12) What is the difference between ApplicationContext and BeanFactory in Spring framework?

13) How do you call stored procedure by using Spring framework?

14) What does JdbcTemplate and JmsTemplate class offer in Spring?

15) Can we use more than one configuration file for our Spring project?

16) Explain Spring MVC flow with a simple example e.g. starting from Container receives a request and forward to your Java application ?

17) What is the difference in Spring MVC and Spring core?

18) Can you use Spring MVC framework along with Struts ? I have an existing Java MVC application which is based in Struts, Can I migrate that to use Spring MVC ? How ?

19) What is the advantage of Spring MVC framework over Struts 1.0 or Struts 2.0 ? is it worth to convert an existing Struts application to Spring MVC ?

20) How do Spring resolves view returned by ModelAndView class ?

Some Spring MVC questions are tricky e.g. Struts and Spring integration and can be only answered by experienced Java program with 2 to 4-year experience in Spring MVC framework.


21) If a user checked in CheckBox and got a validation error in other fields and then he unchecked the CheckBox, what would be selection status in command object in Spring MVC ? How do you fix this issue?
Since during HTTP post, if the checkbox is unchecked than HTTP does include a request parameter for checkbox, which means updated selection won't be picked up. you can use hidden form field, starting with _ to fix this in Spring MVC. quite a tricky question to answer if you are not aware of HTTP POST behavior and Spring MVC.

Spring Interview Questions and Answers


22) What are different implementations of View interface you have used in Spring MVC?
ULBased View e.g. JSP , JSTLView,


23) How to escape HTML special characters using Spring MVC?
There are some methods in Spring tag library, can't remember now.


These were some of the Core Spring framework and MVC Interview questions from my collection, I have given short answers for most of these Spring interview question. I suggest to research more or read along those Spring question to prepare for follow-up Spring interview questions.

Other Interview questions and answer for Java programmer:



References
Spring Documentations
Spring Security Project Documentation
Spring in Action 

11 comments:

  1. My list of Spring MVC interview question :

    Explain Spring MVC flow with a simple example e.g. starting from Container receives request and forward to your Java application ?

    What is difference in Spring MVC and Spring core?

    Can you use Spring MVC framework along with Struts ? I have an existing Java MVC application which is based in Struts, Can I migrate that to use Spring MVC ? How ?

    What is advantage of Spring MVC framework over Struts 1.0 or Struts 2.0 ? is it worth to convert an existing Struts application to Spring MVC ?

    How does Spring resolves view returned by ModelAndView class ?

    Some Spring MVC questions are tricky e.g. Struts and Spring integration and can be only answered by experienced Java program with 2 to 4 year experience in Spring MVC framework.

    ReplyDelete
    Replies
    1. Good questions Radhe. Inspired by you, I would also like to share few more Spring MVC question which I have seen on Spring Interviews :

      1)IF User checked in CheckBox and got validation error on otherfields and than he unchecked the CheckBox, what would be selection status in command object in Spring MVC ? How do you fix this issue ?
      Since during HTTP post, if checkbox is unchecked than HTTP does include a request parameter for checkbox, which means updated selection won't be picked up. you can use hidden form field, starting with _ to fix this in Spring MVC. quite tricky question to answer if you are not aware of HTTP POST behavior and Spring MVC.

      2) What are different implementation of View interface you have used in Spring MVC ?
      ULBased View e.g. JSP , JSTLView,

      3) How to escape HTML special characters using Spring MVC ?
      there are some methods in Spring tag library, can't remember now.

      Delete
  2. Nice answer bhaumik, Can't remember now!

    ReplyDelete
  3. Please explain what is difference between spring mvc and struts 2.0?

    ReplyDelete
  4. Does anyone know the answers to the other questions?

    ReplyDelete
  5. both are used for web layer but spring MVC provide extra features

    ReplyDelete
  6. Please explain Spring MVC Controllers what are the different Cotrollers available and how to use it.and how those better then struts Action classes.

    ReplyDelete
  7. These qustions are quite good to test candidates with 1 to 3 year of experience. You can ask these questions on phone interviews as well, I have added in my own list. I particularly like the diffrence between singlton and request scope difference and whether spring beans are thread-sfae or not.

    ReplyDelete
  8. Hi Paul, amazing questions and answers.
    Regarding questions 22 there is many more classes in Spring that implement that interface. I popular example would be the TilesView class. Be careful if you use the latter because there are two: org.springframework.web.servlet.view.tiles3.TilesView and org.springframework.web.servlet.view.tiles2.TilesView and the behaviour is slightly changes.
    For this kind of questions and more you can visit our SpringCore web simulator at https://www.springmockexams.com/

    ReplyDelete
  9. Even though Spring is not part of core java I increasingly see questions from Spring in core Java interviews. thanks for sharing these, hope you could share some more questions related to performance and security aspect of Spring framework.

    ReplyDelete