Spring Interview Question is one of the first thing 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 upon your work experience, Interviewer can asked 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 Questions and AnswersAnyway 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 ?
default scope of bean is Singleton, 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 to inject dependency on Object, instead of object resolving 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 controller in Spring ?
8) What is view Resolver pattern ? how it work in Spring MVC
View Resolver patter 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 view, which is than passed to View Resolver for selecting 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 user from database, LDAP and in memory, concurrent active session management support and many 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.
10) How do you control concurrent Session on Java web application using Spring Security.
see this Spring Security example on 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?
12) What is 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?
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:
5 Thread interview questions answers in Java
10 Java Coding Interview questions and Answer
10 Advanced core Java interview questions
What are difference between wait and sleep in Java