Spring Interview Questions and Answer for Experienced

Categories: Interview questions and answers Experienced Freshers Spring

Question:-  What is Spring Framework?

Answer :-Spring is a powerful open-source, loosely coupled, lightweight, java framework meant for reducing the complexity of developing enterprise-level applications. This framework is also called the “framework of frameworks” as spring provides support to various other important frameworks like JSF, Hibernate, Structs, EJB, etc.

There are around 20 modules which are generalized into the following types:

  1. Core Container
  2. Data Access/Integration
  3. Web
  4. AOP (Aspect Oriented Programming)
  5. Instrumentation
  6. Messaging
  7. Test

Answer :-  The main idea in Dependency Injection is that you don’t have to create your objects but you just have to describe how they should be created.

  • The components and services need not be connected by us in the code directly. We have to describe which services are needed by which components in the configuration file. The IoC container present in Spring will wire them up together.
  • In Java, the 2 major ways of achieving dependency injection are:

  1. Constructor injection: Here, the IoC container invokes the class constructor with a number of arguments where each argument represents a dependency on the other class.
  2. Setter injection: Here, the spring container calls the setter methods on the beans after invoking a no-argument static factory method or default constructor to instantiate the bean.

Question:- Explain the difference between constructor and setter injection?

Answer :-
  •  In constructor injection, partial injection is not allowed whereas it is allowed in setter injection.
  • The constructor injection doesn’t override the setter property whereas the same is not true for setter injection.
  • Constructor injection creates a new instance if any modification is done. The creation of a new instance is not possible in setter injection.
  • In case the bean has many properties, then constructor injection is preferred. If it has few properties, then setter injection is preferred.

Question:- What is the Bean life cycle in Spring Bean Factory Container?

Answer :- Bean life cycle in Spring Bean Factory Container is as follows: 

  1. The Spring container instantiates the bean from the bean’s definition in the XML file.
  2. Spring populates all of the properties using the dependency injection, as specified in the bean definition.
  3. The factory calls setBeanName() by passing the bean’s ID, if the bean implements the BeanNameAware interface.
  4. The factory calls setBeanFactory() by passing an instance of itself, if the bean implements the BeanFactoryAware interface.
  5. preProcessBeforeInitialization() methods are called if there are any BeanPostProcessors associated with the bean.
  6. If an init-method is specified for the bean, then it will be called.
  7. Finally, postProcessAfterInitialization() methods will be called if there are any BeanPostProcessors associated with the bean.

Question:- What do you understand by auto wiring and name the different modes of it?

Answer :- 

The Spring container is able to autowire relationships between the collaborating beans. That is, it is possible to let Spring resolve collaborators for your bean automatically by inspecting the contents of the BeanFactory.

Different modes of bean auto-wiring are:


a. no: This is default setting which means no autowiring. Explicit bean reference should be used for wiring.

b. byName: It injects the object dependency according to name of the bean. It matches and wires its properties with the beans defined by the same names in the XML file.

c. byType: It injects the object dependency according to type. It matches and wires a property if its type matches with exactly one of the beans name in XML file.

d. constructor: It injects the dependency by calling the constructor of the class. It has a large number of parameters.

e. autodetect: First the container tries to wire using autowire by constructor, if it can’t then it tries to autowire by byType.


Question:- What are the limitations with auto wiring?

Answer :-  Following are some of the limitations you might face with auto wiring:


  • Overriding possibility: You can always specify dependencies using <constructor-arg> and <property> settings which will override autowiring.
  • Primitive data type: Simple properties such as primitives, Strings and Classes can’t be autowired.
  • Confusing nature: Always prefer using explicit wiring because autowiring is less precise.

Question:- What are the bean scopes available in Spring?

  • Answer :- The Spring Framework has five scope supports. They are:

  • Singleton: The scope of bean definition while using this would be a single instance per IoC container.
  • Prototype: Here, the scope for a single bean definition can be any number of object instances.
  • Request: The scope of the bean definition is an HTTP request.
  • Session: Here, the scope of the bean definition is HTTP-session.
  • Global-session: The scope of the bean definition here is a Global HTTP session.

Question:- What is Annotation-based container configuration? Also, explain how to turn on annotation wiring in Spring Framework.

Answer :-  Annotation-based container configuration is an alternative to XML setups. Rather than using XML for describing a bean wiring, the developer moves the configuration to the component class by using annotations on the appropriate class, field, or method declaration.


Because annotation wiring is turned off by default, it needs to be turned on before it can be used. It is done by configuring the <context:annotation-config/> element in the Spring configuration file.


Question:- What do you mean by Spring DAO support?

Answer :- The Spring DAO support eases working with data access technologies, such as JDBC, JDO, and Hibernate, in a reliable way. Also, it allows coding without worrying about catching specific-technology exceptions and easily makes a switch amongst persistence technologies.

Question:- What do you understand by Bean Wiring.

Answer :- 

  • When beans are combined together within the Spring container, they are said to be wired or the phenomenon is called bean wiring.
  • The Spring container should know what beans are needed and how the beans are dependent on each other while wiring beans. This is given by means of XML / Annotations / Java code-based configuration.

Question:- What is Advice in Spring? Explain its various types.

Answer :-  Any action taken by an aspect at some particular joinpoint in Spring Framework is called an Advice. Spring AOP makes use of advice for maintaining a chain of interceptors “around” the joinpoint i.e. as an interceptor. Advice can be of the following types:

  1. After (finally) – Configured using the @After annotation mark, it is executed after a joinpoint method, whether exiting normally or throwing an exception
  2. After returning – Configured using the @AfterReturning annotation mark, it is executed right after the joinpoint method completes normal execution
  3. After throwing – Configured using the @AfterThrowing annotation mark, it is executed if and only if the jointpoint method exits by throwing an exception
  4. Around – Configured using the @Around annotation mark, it is executed before as well as after a joinpoint method
  5. Before – Configured using the @Before annotation mark, it is executed before the joinpoint method

Question:- Could you draw a comparison between concern and crosscutting concerns in Spring AOP?

Answer :- While the concern is a behavior that the developer wants to have in a particular module of a Spring application, the cross-cutting concern is a concern that is applicable throughout the entire Spring application.

Question:- What do you understand by the term ‘Spring Boot’?

Answer :- Spring Boot is an open-source, java-based framework that provides support for Rapid Application Development and gives a platform for developing stand-alone and production-ready spring applications with a need for very few configurations.

Question:- Differentiate between Spring and Spring Boot.

Answer :- 

  • The Spring Framework provides multiple features like dependency injection, data binding, aspect-oriented programming (AOP), data access, and many more that help easier development of web applications whereas Spring Boot helps in easier usage of the Spring Framework by simplifying or managing various loosely coupled blocks of Spring which are tedious and have a potential of becoming messy.
  • Spring boot simplifies commonly used spring dependencies and runs applications straight from a command line. It also doesn’t require an application container and it helps in monitoring several components and configures them externally.

 Question:- What is Hibernate ORM Framework?

Answer :- 

  • Object-relational mapping (ORM) is the phenomenon of mapping application domain model objects to the relational database tables and vice versa.
  • Hibernate is the most commonly used java based ORM framework.

Question:- What is the Spring MVC framework?

Answer :- 

  • Spring MVC is request driven framework and one of the core components of the Spring framework.
  • It comes with ready to use loosely coupled components and elements that greatly aids developers in building flexible and robust web applications.
  • The MVC (Model - View - Controller) architecture separates and provides loose coupling between the different aspects of the application – input logic (Model), business logic (Controller), and UI logic (View).

Question:- What are the ways by which Hibernate can be accessed using Spring?

Answer :- There are two ways by which we can access Hibernate using Spring:

a. Inversion of Control with a Hibernate Template and Callback.

b. Extending HibernateDAOSupport and Applying an AOP Interceptor node.

Question:- What is a Pointcut in Spring?

Answer :- Pointcut is an expression language of Spring AOP.

Question:- What are the different latest versions of Spring framework?

Answer :- 

The latest versions of the Spring framework are as follows.

  1. Spring 2.5
  2. Spring 3.0
  3. Spring 4.0

  • Question:- What is weaving in the Spring framework?
  • Answer :-  Weaving in Spring framework is the process of linking a particular aspect with other application types or objects so that an advised object is created. It is performed mostly during Runtime.
  • Question:- What is the role of @ModelAttribute annotation?

    Answer :-  The annotation plays a very important role in binding method parameters to the respective attribute that corresponds to a model. Then it reflects the same on the presentation page. The role of the annotation also depends on what the developer is using that for. In case, it is used at the method level, then that method is responsible for adding attributes to it. When used at a parameter level, it represents that the parameter value is meant to be retrieved from the model layer.

    Question:- Can Spring Boot allow Spring MVC or Spring WebFlux in the same application?

    Answer :- Yes, Spring Boot can allow either Spring MVC or Spring WebFlux in the same application but with the condition to apply only one at a time. This is because MVC is a blocking paradigm, and WebFlux is a non-blocking paradigm and hence cannot be used together.


Top articles
Servlet interview questions and answers for experienced Published at:- Spring Interview Questions and Answer for Experienced Published at:- Spring Boot Features for Java Developers (2022) Published at:- Detecting build version and time at runtime in Spring Boot Published at:- AWS Interview Questions Answers for Freshers and Experienced Published at:- Laravel Interview Question Answer for Freshers and Experienced Published at:- Splunk Interview Questions and Answers for freshers and Experienced Published at:- IOS Interview Questions for freshers and experienced Published at:- Red Hat Interview Question Answers for Freshers and experienced Published at:- Python Interview Question and Answer Published at:- Basic Indian History General Knowledge Question and Answer (Quiz) Published at:- AWS Interview Question and Answer for freshers and Experienced Published at:- Angular 13 interview Question and Answer Published at:- Question bank for Limited Departmental Competitive Examination (LDC) examination Published at:- Question bank for Limited Departmental Competitive Examination (LDC) examination (Set 2) Published at:- Question bank for Limited Departmental Competitive Examination (LDC) examination (Set 3) Published at:- Limited Departmental Competitive examination (LDC) examination (Water supply) Published at:- Interview Question and answer for Limited Departmental Competitive Examination Published at:- Question bank for Limited Departmental Competitive Examination (LDC) examination (Soil mechanics) Published at:- Question bank for Limited Departmental Competitive Examination (LDC) examination Sanitary Engineering Published at:- Interview Question for Limited Departmental Competitive Examination (LDC) Principles of Surveying Published at:- Interview MCQ question for railways New Lines, Doublings & Gauge Conversion Projects Published at:- MCQ Interview Question and answer for Railway Station and Passenger Amenities Published at:- Interview Question and Answer for Railway preparation Published at:- PHP MCQ Quiz Question with Answer Published at:- PHP MCQ Quiz Question with Answer (set 2) Published at:- Angular MCQ Quiz Question and Answer Published at:- Angular MCQ Quiz Question and Answer Set 2 Published at:- Java General Interview Questions and Answer Published at:- Java Threads Interview Question and Answer for experienced Published at:- Java Collections Interview Question and Answer for freshers and experienced Published at:- Garbage Collector in Java Frequently Asked Questions and Answers Published at:- Difference between Exception and Error in java Exception Handling Published at:- Java Applets Interview Questions with Answer Published at:- Java Swing Interview Questions with Answer for freshers and experienced Published at:- Java Database Connectivity (JDBC) Interview Question and answer Published at:- Remote Method Invocation (RMI) Interview Question and Answer Published at:- Jakarta Server Page (JSP) programming language Interview Question and Answer Published at:- Write a program in Java to display the first 10 terms of the following series: 10, 20, 30, 40, …….. Published at:- Write the program in Java to display the first ten terms of the following series: 1, 4, 9, 16, Published at:-
R4Rin Team
The content on R4Rin.com website is created by expert teams.