Spring FAQs – Top 30 Spring interview questions and answers

You may also like:

  1.  Top 30 Core-Java interview questions and answers
  2. Jsp Servlet Interview Questions
  3. Junit Interview Questions and Answers
  4. JSP interview questions and answers for senior developers

Recently added questions

Question: What is Controller in Spring MVC framework?
Ans: In a general way, Controller (‘c’ in mvc ) delivers access to the behavior of application which is usually defined by a service interface and acts as glue between core application and the web. It processes/interprets client data and.. Read More

Question: What is a front controller in Spring MVC ?
Ans: A front controller is defined as “a controller which handles all requests for a Web Application.” DispatcherServlet (actually a servlet) is the front controller in Spring MVC that intercepts every request and then dispatches/forwards requests to an appropriate controller.. Read More

Question: What is SimpleFormController in Spring MVC and how to use it in your web application ?
Ans:It offers you form submission support. This can help in modeling forms and populating them with model/command object returned by the controller. After filling the form, it binds the fields, validates the model/command object, and passes the object back to the controller so that the controller can take appropriate action.. Read More

Question: Why to override formBackingObject(HttpServletRequest request) method in Spring MVC?
Ans:You should override formBackingObject(HttpServletRequest request) if you want to provide view with model object data so that view can be initialized with some default values e.g. Consider in your form view.. Read More
Question: What are the advantages of Spring MVC over Struts MVC ?
Ans: 1. There is clear separation between models, views and controllers in Spring.
2. Spring’s MVC is very versatile and flexible based on interfaces but Struts forces Actions and Form object into concrete inheritance.
3. Spring provides both interceptors and controllers.. Read More
To see Spring MVC hello world example click here

Question: Difference between FileSystemResource and ClassPathResource ?
Ans: In FileSystemResource you need to give path of spring-config.xml (Spring Configuration) file relative to your project or the absolute location of the file.
You can get this by right-clicking the spring-config.xml … Read More

Question: Difference between BeanFactory and ApplicationContext ?
Ans: BeanFactory instantiates beans lazily i.e. Beans are instantiated when you get them from BeanFactory not on loading BeanFactory.

 BeanFactory beanFactory = new XMLBeanFactory(new ClassPathResource("spring-beans.xml")); // factory is loaded,
Emp emp = beanFactory.getBean(''empBean''); // bean is instantiated

Read More

Question: How to customize bean destruction process ?
Ans: The Spring offers several callback interfaces to modify the behaviour of your bean. By implementing DisposableBean interface Spring Container will call destroy() method … Read More

Question: How to customize bean initialization process ?
Ans: The Spring offers several callback interfaces to modify the behaviour of your bean. By implementing InitializingBean interface Spring Container will call afterPropertiesSet() method … Read More

Question: How to implement inheritance in Bean definition ?
Ans: Inheritance can be implemented by specifying the ‘parent’ attribute in bean tag and passing id of (parent) the bean that you want to inherit .
In the example below … Read More

Question: Explain inner bean in Spring ?
Ans: A bean which is defined (embedded) inside the property tag of other bean is called an inner bean. Inner beans can not be used (referred) by other beans except the enclosing one …. Read More

Question: What is Dependency Injection in Spring ?
Ans: In spring objects define their associations (dependencies) and do not worry about how to get those dependencies ; now it is the responsibility of Spring to provide the required dependencies for creating objects … Read More

Question: What is Inversion of Control in spring ?
Ans: IOC means inverting the control of creating the object from our own using new operator to Spring container …Read More

Question: What are different types of injection in Spring ?
Ans: Three types of injection in Spring3 Framework
(1) Setter Injection
(2) Constructor Injection
(3) Getter or Method Injection

Question: Benefits of using Spring Framework ?
Ans: Spring is relatively light weight container in comparison to other J2EE containers. It does not use much memory and CPU cycles for loading beans, providing services like transaction control , AOP management, JDBC interaction. …Read More

Question: Describe different modules of Spring Framework ?
Ans: Spring comprises of the following modules.
Core container : Basic functionality of Spring is provided by the core container. BeanFactory is the primary component of core container, an implementation of the Factory design pattern. …Read More

Question: What is BeanFactory ?
Ans: BeanFactory ( org.springframework.beans.factory.BeanFactory an interface) acts as Spring IoC container that is responsible for containing, configuring and managing the application beans. …Read More

Question: What is XmlBeanFactory ?
Ans: There are a many implementations of the BeanFactory interface. XmlBeanFactory class is most common implementation of BeanFactory. …Read More

Question: What is ApplicationContext ?
Ans: ApplicationContext ( org.springframework.context.ApplicationContext ) is an interface which makes Spring a framework. It is derivd from BeanFactory, so has all the functionality of BeanFactory and adds lots more. …Read More

Question: What are the common implementations of the Application Context ?
Ans: ClassPathXmlApplicationContext : It loads the context definition from an XML file present in the classpath, treating context definitions as classpath resources. …Read More

Question: What is Bean wiring ?
Ans: The process of linking (associating) beans with each other within a Spring container is called bean wiring. All the Spring managed beans of the application needs to be defined in an xml file …Read More

Question: What is auto wiring ?
Ans: The Spring container provides the functionality of connecting beans with each other automatically called autowiring . Rather we inject one bean into the other using ref attribute,  Spring can look into the BeanFactory and decide how to inject one bean into the other …Read More

Question: What are the different bean scopes in Spring ? Explain with an example ?
Ans: In Spring, creation of beans can be controlled by defining the scope of bean.  To define scope attribute ‘scope’ of <bean> tag is used. There are five types of bean scopes in Spring …Read More

Question: What is Aspect Oriented programming (AOP) ? Explain with an example ?
Ans: AOP is a programming technique used to manage cross-cutting concerns like logging, security and transaction management. To implement AOP we need to create aspects (classes) which contains cross-cutting functionality …Read More
To see AOP implementation examples click here

Question: What is the difference between concerns and cross-cutting concerns ?
Ans: Concern is behavior which we want to have in a module of an application. Concern may be defined as a functionality we want to implement. Issues in which we are interested defines our concerns …Read More
To see AOP implementation examples click here

Question: What is Aspect in Spring AOP? Explain with an example ?
Ans: Aspect defines the implementation of cross-cutting concern. We implement a cross-cutting functionality by creating an aspect. Aspect encapsulates our cross-cutting concern …Read More
To see AOP implementation examples click here

Question: What is Advice in Spring AOP ? Explain with an example ?
Ans: Action performed by an aspect at a particular join point is called an Advice. Different types of advice are “around,” “before” ,”after”, “afterreturning” and “afterthrowing” …Read More
To see AOP implementation examples click here

Question: What is Pointcut in Spring AOP ? Explain with an example ?
Ans: A pointcut is an expression/predicate which points to a join point. Pointcut defines where to hook the advice …Read More
To see AOP implementation examples click here

Question: What is join point ? Explain with an example ?
Ans: Join point represents execution of a method where we want to hook the advice into.
Consider execution of a program and during this some methods are called say meth1(), meth2(), meth3() …Read More
To see AOP implementation examples click here

Question: What is Around advice ? Explain with an example ?
Ans: This advice is combination of before and after advices. It lets you do something before target method (join point) and some other things after the target method (join point) …Read More
To see AOP implementation examples click here

Question: Explain Spring MVC framework with an example ?
Ans: Explain Spring MVC architecture with an example ? The MVC is a standard software architecture that aims to separate business logic from presentation logic, enabling the development, testing and maintenance of both isolated . (1) The user triggers an event through the UI (click a button on the page or something).
(2) The controller receives the event and coordinates how things will happen on the server side, i.e. the flow goes to the objects required to perform the business rule.. Read More
To see Spring MVC hello world example click here