Spring Interview Questions and Answers, Spring Interview Questions and Answers Freshers, Spring Interview Questions and Answers, Spring Interview Questions

Before getting on to the Spring interview questions, the student must know that the Hadoop is a continuously varying field which needs the students as well as professionals to upgrade their skills with the new features and knowledge, to get fit for the jobs associated. This post related to Spring Interview Questions and Answers, Spring Interview Questions and Answers Freshers, Spring Interview Questions and Answers, Spring Interview Questions will help you let out find all the solutions that are frequently asked in you upcoming Spring interview

Over thousands of vacancies available for the Spring developers, experts must be acquaintance with all the component of Spring technologies. This is necessary for the students in order to have in-depth knowledge of the subject so that they can have best employment opportunities in the future. Knowing every little detail about Spring is the best approach to solve the problems linked with problem.

APTRON has spent hours and hours in researching about the Spring Interview Questions and Answers, Spring Interview Questions and Answers Freshers, Spring Interview Questions and Answers, Spring Interview Questions that you might encounter in your upcoming interview. This post related to Spring interview questions and answers will help you let out find all the solutions that are frequently asked in you upcoming Spring interview. All these questions will alone help you to crack the interview and make you the best among all your competitors.

First of all, let us tell you about how the Spring technology is evolving in today’s world and how demanding it is in the upcoming years. In fact, according to one study, most of the companies and businesses have moved to the Spring . Now, you cannot predict how huge the future is going to be for the people experienced in the related technologies.

Hence, if you are looking for boosting up your profile and securing your future, Spring will help you in reaching the zenith of your career. Apart from this, you would also have a lot of opportunities as a fresher.

These questions alone are omnipotent. Read and re-read the questions and their solutions to get accustomed to what you will be asked in the interview. These Spring interview questions and answers will also help you on your way to mastering the skills and will take you to the giant world where worldwide and local businesses, huge or medium, are picking up the best and quality Spring professionals.

This ultimate list of best Spring interview questions will ride you through the quick knowledge of the subject and topics like OOPS, SPRING, HIBERNATE. This Spring interview questions and answers can be your next gateway to your next job as a Spring expert.

These are very Basic Spring Interview Questions and Answers for freshers and experienced both.

Q1: What is Spring Framework?
A1: Spring is one of the most widely used Java EE framework. Spring framework core concepts are “Dependency Injection” and “Aspect Oriented Programming”.

Spring framework can be used in normal java applications also to achieve loose coupling between different components by implementing dependency injection and we can perform cross cutting tasks such as logging and authentication using spring support for aspect oriented programming.

I like spring because it provides a lot of features and different modules for specific tasks such as Spring MVC and Spring JDBC. Since it’s an open source framework with a lot of online resources and active community members, working with Spring framework is easy and fun at same time.

Q2: What do you understand by Dependency Injection?
A2: Dependency Injection design pattern allows us to remove the hard-coded dependencies and make our application loosely coupled, extendable and maintainable. We can implement dependency injection pattern to move the dependency resolution from compile-time to runtime.

Some of the benefits of using Dependency Injection are: Separation of Concerns, Boilerplate Code reduction, Configurable components and easy unit testing.

Read more at Dependency Injection Tutorial. We can also use Google Guice for Dependency Injection to automate the process of dependency injection. But in most of the cases we are looking for more than just dependency injection and that’s why Spring is the top choice for this.

Q3: How do we implement DI in Spring Framework?
A3: We can use Spring XML based as well as Annotation based configuration to implement DI in spring applications. For better understanding, please read Spring Dependency Injection example where you can learn both the ways with JUnit test case. The post also contains sample project zip file, that you can download and play around to learn more.

Q4: What are the benefits of using Spring Tool Suite?
A4: We can install plugins into Eclipse to get all the features of Spring Tool Suite. However STS comes with Eclipse with some other important stuffs such as Maven support, Templates for creating different types of Spring projects and tc server for better performance with Spring applications.

I like STS because it highlights the Spring components and if you are using AOP pointcuts and advices, then it clearly shows which methods will come under the specific pointcut. So rather than installing everything on our own, I prefer using STS when developing Spring based applications.

Q5: Name some of the important Spring Modules?
A5: Some of the important Spring Framework modules are:

  • Spring Context– for dependency injection.
  • Spring AOP– for aspect oriented programming.
  • Spring DAO– for database operations using DAO pattern
  • Spring JDBC– for JDBC and DataSource support.
  • Spring ORM– for ORM tools support such as Hibernate
  • Spring Web Module– for creating web applications.
  • Spring MVC– Model-View-Controller implementation for creating web applications, web services etc.

Q6: What is the difference between Spring AOP and AspectJ AOP?
A6: AspectJ is the industry-standard implementation for Aspect Oriented Programming whereas Spring implements AOP for some cases. Main differences between Spring AOP and AspectJ are:

  • Spring AOP is simpler to use than AspectJ because we don’t need to worry about the weaving process.
  • Spring AOP supports AspectJ annotations, so if you are familiar with AspectJ then working with Spring AOP is easier.
  • Spring AOP supports only proxy-based AOP, so it can be applied only to method execution join points. AspectJ support all kinds of pointcuts.
  • One of the shortcoming of Spring AOP is that it can be applied only to the beans created through Spring Context.

Q7: What is a Spring Bean?
A7: Any normal java class that is initialized by Spring IoC container is called Spring Bean. We use Spring ApplicationContext to get the Spring Bean instance.

Spring IoC container manages the life cycle of Spring Bean, bean scopes and injecting any required dependencies in the bean.

Q8: What are features of Spring?
A8: Lightweight:

Spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 1MB. And the processing overhead is also very negligible.

Inversion of control (IOC):

Loose coupling is achieved in spring using the technique Inversion of Control. The objects give their dependencies instead of creating or looking for dependent objects.

Aspect oriented (AOP):

Spring supports Aspect oriented programming and enables cohesive development by separating application business logic from system services.


Spring contains and manages the life cycle and configuration of application objects.

MVC Framework:

Spring comes with MVC web application framework, built on core Spring functionality. This framework is highly configurable via strategy interfaces, and accommodates multiple view technologies like JSP, Velocity, Tiles, iText, and POI. But other frameworks can be easily used instead of Spring MVC Framework.

JDBC Exception Handling:

The JDBC abstraction layer of the Spring offers a meaningful exception hierarchy, which simplifies the error handling strategy. Integration with Hibernate, JDO, and iBATIS: Spring provides best Integration services with Hibernate, JDO and iBATIS.

Transaction Management:

Spring framework provides a generic abstraction layer for transaction management. This allowing the developer to add the pluggable transaction managers, and making it easy to demarcate transactions without dealing with low-level issues. Spring’s transaction support is not tied to J2EE environments and it can be also used in container less environments.

Q9: What is Spring Java Based Configuration?
A9: Java based configuration option enables the user to write most of their Spring configuration without XML but with the help of few Java-based annotations.

for example:

Annotation @Configuration indicates that the class can be used by the Spring IoC container as a source of bean definitions. The @Bean annotation tells spring that a method annotated with @Bean will return an object that should be registered as a bean in the spring application context.

Q10: What are the types of Dependency Injection Spring supports?
A10: Setter Injection

Setter-based DI is realized by calling setter methods on the user’s beans after invoking a no-argument constructor or no-argument static factory method to instantiate their bean.

Constructor Injection

Constructor-based DI is realized by invoking a constructor with a number of arguments, each representing a collaborator.

Q11: What are Spring beans?
A11: The objects that form the backbone of the users application and that are managed by the Spring IoC container are called beans. A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. These beans are created with the configuration metadata that the users supply to the container.

Q12: What is the difference between BeanFactory and ApplicationContext?
A12: BeanFactory is the basic container whereas ApplicationContext is the advanced container. ApplicationContext extends the BeanFactory interface. ApplicationContext provides more facilities than BeanFactory such as integration with spring AOP, message resource handling for i18n etc.

Q13: What are the different bean scopes in spring?
A13: There are 5 bean scopes in spring framework.

No. Scope Description
1) singleton The bean instance will be only once and same instance will be returned by the IOC container. It is the default scope.
2) prototype The bean instance will be created each time when requested.
3) request The bean instance will be created per HTTP request.
4) session The bean instance will be created per HTTP session.
5) globalsession The bean instance will be created per HTTP global session. It can be used in portlet context only.

Q14: In which scenario, you will use singleton and prototype scope?
A14: Singleton scope should be used with EJB stateless session bean and prototype scope with EJB stateful session bean.

Q15: Does spring framework support all JoinPoints?
A15: No, spring framework supports method execution joinpoint only.

Q16: What is Advice?
A16: Advice represents action taken by aspect.

Q17: What is interceptor?
A17: Interceptor is a class like aspect that contains one advice only.

Q18: Give an example of BeanFactory implementation.
A18: The most commonly used BeanFactory implementation is the XmlBeanFactory class. This container reads the configuration metadata from an XML file and uses it to create a fully configured system or application.

Q19: How can you inject Java Collection in Spring?
A19: Spring offers four types of collection configuration elements which are as follows −

  • <list>− This helps in wiring i.e. injecting a list of values, allowing duplicates.
  • <set>− This helps in wiring a set of values but without any duplicates.
  • <map>− This can be used to inject a collection of name-value pairs where name and value can be of any type.
  • <props>− This can be used to inject a collection of name-value pairs where the name and value are both Strings.

Q20: What are different Modes of auto-wiring?
A20: The autowiring functionality has five modes which can be used to instruct Spring container to use autowiring for dependency injection −

  • no− This is default setting which means no autowiring and you should use explicit bean reference for wiring. You have nothing to do special for this wiring. This is what you already have seen in Dependency Injection chapter.
  • byName− Autowiring by property name. Spring container looks at the properties of the beans on which autowire attribute is set to byName in the XML configuration file. It then tries to match and wire its properties with the beans defined by the same names in the configuration file.
  • byType− Autowiring by property datatype. Spring container looks at the properties of the beans on which autowire attribute is set to byType in the XML configuration file. It then tries to match and wire a property if its type matches with exactly one of the beans name in configuration file. If more than one such beans exist, a fatal exception is thrown.
  • constructor− Similar to byType, but type applies to constructor arguments. If there is not exactly one bean of the constructor argument type in the container, a fatal error is raised.
  • autodetect− Spring first tries to wire using autowire by constructor, if it does not work, Spring tries to autowire by byType.

Q21: What is Weaving?
A21: Weaving is the process of linking aspects with other application types or objects to create an advised object.

Q22: What is Spring MVC framework?
A22: 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 of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements.

Q23: What is WebApplicationContext?
A23: The WebApplicationContext is an extension of the plain ApplicationContextthat has some extra features necessary for web applications. It differs from a normal ApplicationContext in that it is capable of resolving themes, and that it knows which servlet it is associated with.

Q24: What is Controller in Spring MVC framework?
A24: Controllers provide access to the application behavior that you typically define through a service interface. Controllers interpret user input and transform it into a model that is represented to the user by the view. Spring implements a controller in a very abstract way, which enables you to create a wide variety of controllers.

Q25: How is a typical spring implementation look like?
A25: For a typical Spring Application we need the following files:

  • An interface that defines the functions.
  • An Implementation that contains properties, its setter and getter methods, functions etc.,
  • Spring AOP (Aspect Oriented Programming)
  • A XML file called Spring configuration file.
  • Client program that uses the function.

Q26: What is DelegatingVariableResolver?
A26: Spring provides a custom JavaServer Faces VariableResolver implementation that extends the standard Java Server Faces managed beans mechanism which lets you use JSF and Spring together. This variable resolver is called as DelegatingVariableResolver

Q27: What do you mean by Bean wiring?
A27: The act of creating associations between application components (beans) within the Spring container is reffered to as Bean wiring.

Q28: What is Significance of JSF- Spring integration?
A28: Spring – JSF integration is useful when an event handler wishes to explicitly invoke the bean factory to create beans on demand, such as a bean that encapsulates the business logic to be performed when a submit button is pressed.

Q29: How to integrate your Struts application with Spring?
A29: To integrate your Struts application with Spring, we have two options:

  • Configure Spring to manage your Actions as beans, using the ContextLoaderPlugin, and set their dependencies in a Spring context file.
  • Subclass Spring’s ActionSupport classes and grab your Spring-managed beans explicitly using a getWebApplicationContext() method.

Q30: What do you mean by Aspect?
A30: A modularization of a concern that cuts across multiple objects. Transaction management is a good example of a crosscutting concern in J2EE applications. In Spring AOP, aspects are implemented using regular classes (the schema-based approach) or regular classes annotated with the @Aspect annotation (@AspectJ style).

Q31: What are the types of Advice?
A31: Types of advice:

  • Before advice: Advice that executes before a join point, but which does not have the ability to prevent execution flow proceeding to the join point (unless it throws an exception).
  • After returning advice: Advice to be executed after a join point completes normally: for example, if a method returns without throwing an exception.
  • After throwing advice: Advice to be executed if a method exits by throwing an exception.
  • After (finally) advice: Advice to be executed regardless of the means by which a join point exits (normal or exceptional return).
  • Around advice: Advice that surrounds a join point such as a method invocation. This is the most powerful kind of advice. Around advice can perform custom behavior before and after the method invocation. It is also responsible for choosing whether to proceed to the join point or to shortcut the advised method execution by returning its own return value or throwing an exception

Q32: What do you understand by @RequestMapping annotation?
 @RequestMapping annotation is used for mapping a particular HTTP request method to a specific class/ method in controller that will be handling the respective request. This annotation can be applied at both levels:

  • Class level : Maps the URL of the request
  • Method level: Maps the URL as well as HTTP request method

Q33: Name the types of transaction management that Spring supports.
Two types of transaction management are supported by Spring. They are:

  1. Programmatic transaction management: In this, the transaction is managed with the help of programming. It provides you extreme flexibility, but it is very difficult to maintain.
  2. Declarative transaction management: In this, the transaction management is separated from the business code. Only annotations or XML based configurations are used to manage the transactions.

Q34: Describe DispatcherServlet.
 The DispatcherServlet is the core of Spring Web MVC framework. It handles all the HTTP requests and responses. The DispatcherServlet receives the entry of handler mapping from the configuration file and forwards the request to the controller. The controller then returns an object of Model And View. The DispatcherServlet checks the entry of view resolver in the configuration file and calls the specified view component.

Q35: Explain the JDBC abstraction and DAO module
A35: With the JDBC abstraction and DAO module we can be sure that we keep up the database code clean and simple, and prevent problems that result from a failure to close database resources. It provides a layer of meaningful exceptions on top of the error messages given by several database servers. It also makes use of Spring’s AOP module to provide transaction management services for objects in a Spring application.

Q36: Spring configuration file
A36: Spring configuration file is an XML file. This file contains the classes information and describes how these classes are configured and introduced to each other.

Q37: Explain the object/relational mapping integration module
A37: Spring also supports for using of an object/relational mapping (ORM) tool over straight JDBC by providing the ORM module. Spring provides support to tie into several popular ORM frameworks, including Hibernate, JDO, and iBATIS SQL Maps. Spring’s transaction management supports each of these ORM frameworks as well as JDBC.

Q38: Explain Bean lifecycle in Spring framework

  • The spring container finds the bean’s definition from the XML file and instantiates the bean.
  • Spring populates all of the properties as specified in the bean definition (DI).
  • If the bean implements BeanNameAware interface, spring passes the bean’s id to setBeanName()
  • If Bean implements BeanFactoryAware interface, spring passes the beanfactory to setBeanFactory()
  • If there are any bean BeanPostProcessors associated with the bean, Spring calls postProcesserBeforeInitialization()
  • If the bean implements IntializingBean, its afterPropertySet()method is called. If the bean has init method declaration, the specified initialization method is called.
  • If there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() methods will be called.
  • If the bean implements DisposableBean, it will call the destroy()

Spring Conclusion Interview FAQs

We know the list of Spring Interview Questions and Answers, Spring Interview Questions and Answers Freshers, Spring Interview Questions and Answers, Spring Interview Questions is overwhelming but the advantages of reading all the questions will maximize your potential and help you crack the interview. The surprising fact is that this Spring interview questions and answers post covers all the basic of the Spring technology and you have to check out the FAQs of different components of Spring too.

However, you will be asked with the questions in the interview related to the above mentioned questions. Preparing and understanding all the concept of Spring technology will help you strengthen the other little information around the topic.

After preparing these interview questions, we recommend you to go for a mock interview before facing the real one. You can take the help of your friend or a Spring expert to find the loop holes in your skills and knowledge. Moreover, this will also allow you in practicing and improving the communication skill which plays a vital role in getting placed and grabbing high salaries.

Remember, in the interview, the company or the business or you can say the examiner often checks your basic knowledge of the subject. If your basics is covered and strengthened, you can have the job of your dream. The industry experts understand that if the foundation of the student is already made up, it is easy for the company to educate the employ towards advance skills. If there are no basics, there is no meaning of having learnt the subject.

Therefore, it’s never too late to edge all the basics of any technology. If you think that you’ve not acquired the enough skills, you can join our upcoming batch of Spring Training in Noida. We are one of the best institute for Spring in noida which provide advance learning in the field of Spring Course. We’ve highly qualified professionals working with us and promise top quality education to the students.

We hope that you enjoyed reading Spring Interview Questions and Answers, Spring Interview Questions and Answers Freshers, Spring Interview Questions and Answers, Spring Interview Questions and all the FAQs associated with the interview. Do not forget to revise all the Spring interview questions and answers before going for the Spring interview. In addition to this, if you’ve any doubt or query associated with Spring, you can contact us anytime. We will be happy to help you out at our earliest convenience. At last, we wish you all the best for your upcoming interview on Spring Technology.