Spring Interview Questions

Spring Interview Questions | Freshers & Experienced

  • Sharad Jaiswal
  • 07th Dec, 2021

About Spring

Spring is one of the frameworks used in Java for making applications. With the help of the spring framework, the users of Java are able to develop the enterprise application in a much simpler and easier manner in collaboration with the support of several other frameworks such as Hibernate and Struts.

Key Features of Spring

Below are few major features of Spring


Aspect-Oriented Programming

Transaction Management


Dependency Injection

Integration with other frameworks

Practice Best Java Spring Interview Questions and Answers;

Q1. What is Spring Framework?

The Spring Framework is an open-source and one of the most popular Java Enterprise Edition frameworks an open-source application framework that provides infrastructure support for developing Java applications. It handles the infrastructure so you can focus on your application.

Q2. What are some of the important features of Spring Framework?

Some of the important features of Spring Framework are as follows:

  • Spring is a lightweight framework because of its POJO implementation.
  • It provides flexible libraries trusted by developers all over the world. 
  • Spring applications are loosely coupled because of dependency injection.
  •  It provides a powerful abstraction to JEE specifications such as JMS, JDBC, JPA, and JTA.
  • Resource management is a cross-cutting concern, easy to copy and paste everywhere.
  • The use of dependency injection makes the testing easy. 
  •  The Spring community provides support and resources to get you to the next level QuickStart guides, tutorials, videos, and meetup helps a lot.
  • It is more productive because the spring application can integrate with other Spring-based applications. 


Q3. What are some advantages of Spring Framework?

Some of the advantages of Spring Framework are as follows:

  • Solving difficulties of Enterprise application development. 
  • Support Enterprise application development through POJOs. 
  •  The Spring framework has a lot of variables and complications.
  • Easy integration of other frameworks.
  • It enables the developer to create high-performing, reusable, easily testable, and loose coupling enterprise Java applications.
  • It facilitates fast and parallel development.

Q4. What do you understand by Dependency Injection?

Dependency injection is a technique to pass one object's dependencies to another object. It is a broader form of inversion of control that makes a class independent of its dependencies. It is the process of supplying a resource that a given piece of code requires.

Q5. What do you understand by Aspect Oriented Programming?

Aspect-oriented programming also known as AOP is a programming technique in which programmers can modularize the crosscutting concerns or change the behavior that cuts across the various divisions of responsibility. An aspect is a subprogram that is associated with a specific property of a program.

Q6. What is Aspect, Advice, Pointcut, JointPoint and Advice Arguments in AOP?

Aspect - A module in spring that contains a set of APIs, which provides for crosscutting requirements is an Aspect.

Advice - It is the action taken by an aspect at a particular join-point. It is associated with a pointcut expression and runs at any join point matched by the pointcut.

Pointcut - It is a collection of one or more join points where one piece of advice can be executed and can be specified by using patterns as well as expressions.

Joinpoint - It is a point in an application where one can initialize an AOP aspect. It can be also defined as the exact place in the application where the action is said to take place while using the spring framework.

Q7. What is Spring IoC Container?

Spring IOC Container lies at the center of the Spring Framework, which creates the object, wires them together, makes necessary changes in them, and manages their entire life cycle. The IOC container gets the instructions for which objects to assemble, instantiate and configure and by reading the modification metadata provided.

Q8. What is a Spring Bean?

Spring Beans can be defined as the objects that are most important for the user’s application and are managed by the containers of Spring IoC are called beans. It is basically an object that is initialized, put together, and is managed by a Spring IoC container. The beans are created with the help of configuration metadata that are supplied to the container by the users.

Q9. What are different ways to configure a class as Spring Bean?

The different ways to configure a class as Spring Bean are as follows:

XML Configuration - This is the most popular configuration and we can use bean element in context file to configure a Spring Bean.

Java Based Configuration - If you are using only annotations, you can configure a Spring bean using @Bean annotation. This annotation is used with @Configuration classes to configure a spring bean.

Annotation Based Configuration - We can also use @Component, @Service, @Repository, and @Controller annotations with classes to configure them to be as spring bean.

Q10. How to get ServletContext and ServletConfig object in a Spring Bean?

You can implement ServletContextAware and ServletConfigAware interfaces and override the setServletContext() and setServletConfig() methods.

@RequestMapping(value = "/home")
public class HomeController implements ServletContextAware, ServletConfigAware {

private ServletContext context;
private ServletConfig config;

public void setServletConfig( ServletConfig servletConfig) {
this.config = servletConfig;


public void setServletContext(ServletContext servletContext) {
this.context = servletContext;


Q11. What are Bean wiring and @Autowired annotation?

Spring bean autowiring can be defined as the declaration of all the bean dependencies in a Spring configuration file, Spring container can autowire relationships between collaborating beans. It can't be used to inject primitive and string values. @Autowired Annotations is the Spring framework that enables automatic dependency injection.

Q12. What is a Controller in Spring MVC?

In Spring MVC, a controller contains the business logic of an application. The controller class handle requests coming from the client. Then, the controller invokes a business class to process business-related tasks and then redirects the client to a logical view name, which is resolved by Spring's dispatcher servlet in order to render results or output.

Q13. What’s the difference between @Component, @Repository & @Service annotations in Spring?

The difference between @Component, @Repository & @Service annotations in Spring can be stated as @component is used to annotate compound classes, @Repository is a marker for automatic exception translation in the persistence layer, and @service is used for the service layer.

Q14. How to handle exceptions in Spring MVC Framework?

You can handle exceptions in Spring MVC Framework with the help of @ExceptionHandler, by defining a method in the controller class and use the annotation @ExceptionHandler on it.

Q15. How to create ApplicationContext in a Java Program?

You can create ApplicationContext in a Java Program by following the given step:

  • The first step is to create a factory object where we used the framework APIFileSystemXmlApplicationContext to create the factory bean after loading the bean configuration file from the given path. 
  • The second step is used to get the required bean using the getBean() method of the created context.


Q16. What are the minimum configurations needed to create Spring MVC application?

The configurations needed to create the Spring MVC application are as follows:

  • Create a Pom. XML for the Required Libraries.
  • Creating the SpringConfig Class.
  • Replacing Web.
  • Create a Controller Class.
  • Create a JSP Page to Show the Message.

Q17. How to validate form data in Spring Web MVC Framework?

To validate form data in Spring Web MVC Framework you can follow the given approach:

  • Add dependencies to pom.xml file. pom.xml. 
  • Create the bean class. Employee.java. 
  • Create the controller class. In controller class.
  • Provide the entry of controller in the web. xml file. 
  • Define the bean in the xml file. spring-servlet.xml. 
  • Create the requested page. 
  • Create the other view components.


Q18. What is Spring JdbcTemplate class and how to use it?

Spring JdbcTemplate class is the central class in the JDBC core package that simplifies the use of JDBC and helps to avoid common errors. It can be used by executing core JDBC workflow, leaving application code to provide SQL and extract results.

Q19. How would you achieve Transaction Management in Spring?

In spring, Transaction Management can be achieved by JTA transactions or local transactions using JDBC, JPA, Hibernate, or JDO by simply adjusting the configuration files. It can be applied to any class, not merely special classes such as EJBs.

Q20. What is Spring Security?

Spring Security is a powerful and highly customizable authentication and access-control framework used for implementing application-level security in Spring applications. It focuses on providing both authentication and authorization to Java applications.

Q21. How to inject a java.util.Properties into a Spring Bean?

You can inject a java.util.Properties into a Spring Bean by using @Autowired and @Qualifier annotations.

About Author :

  • Author of Spring Interview Questions

    Sharad Jaiswal

    My name is Sharad Jaiswal, and I am the founder of Conax web Solutions. My tech stacks are PHP, NodeJS, Angular, React. I love to write technical articles and programming blogs.

Leave A Comment :

Valid name is required.

Valid name is required.

Valid email id is required.