Inspirational journeys

Follow the stories of academics and their research expeditions

Spring Interview Questions With Answers (2026)

writer

By Mamatha J

Published on Wed, 14 October 2026 17:54

Share:
Spring Interview Questions With Answers (2026)

In the year 2026 a framework keeps coming up in every Java interview, which is Spring Boot. If you are trying to get into Java development or just want to write code that is more efficient and less complicated, this is the library that everyone is focused on. Here’s why. Spring is used by Netflix for microservices, and while Google has its own frameworks, it builds on Spring Boot quite a bit to build cloud applications on GCP.

If you are looking for a strong Java developer job with good pay, opportunity for growth, and excitement throughout your career, start practicing spring programming interview questions now! For best results, align your resume to each specific job offer using AI resume tailoring, as demonstrating exact relevance to the employer's tech stack is crucial. Beyond just formatting, you will also get personalized potential interview questions and a deep analysis of your resume fit to ensure you are fully prepared for the technical screening.


Table of Contents

Spring Programming Interview Questions (Beginner)

1. Spring Framework definitions and benefits.

Spring Framework is a part of the Java framework, which helps to build enterprise applications. The Spring Framework gives developers features such as DI, AOP, and transaction management, so developers can make modular and maintainable applications easily.

Benefits: 

Dependency Injection—Reduces tight coupling; creates objects through injection.

  •  AOP Support—Manages cross-cutting concerns like logging or security.
  •  Transaction Management—More straightforward database transactions through annotations.
  • Integration—It supports JDBC, JPA, JMS, REST, etc.
  • Testability—Mocking and unit testing are more manageable.

Are you preparing for a Java job? These spring programming interview questions are here to make your preparation easy and effective!

2. What are dependency injection and inversion of control? How are they implemented in Spring?

 In the Spring Framework, dependency injection and inversion of control are ideas, and they make it easy to change and maintain an application.

Inversion of control is, if you are writing code to create objects and control how they work, you would let a central Spring IoC container handle all of that. The container takes charge of creating objects and managing their lifecycle.

Dependency injection is the way that Spring supports inversion of control. It works by giving an object the dependencies it needs. Without the object having to build or search for them itself. This makes code more modular and simpler to test.

. DI means that Spring will provide the appropriate dependencies as needed instead of the object creating its own dependencies. If you have an Employee object that requires an Address object, then DI indicates that Spring will create the Address object and provide it to the Employee. (If you're documenting your architecture decisions for a team, a booklet maker can help turn your notes into something easier to share and reference.)

Spring can inject dependencies in three ways:

  •   Constructor Injection: Provide the dependencies in the class constructor.
  •  Setter Injection: Set the instance variable via setter methods.
  • Field Injection: Use annotations directly on the instance variables (this option is less practical).

3. What are Spring Beans? What is their scope and default scope?

Spring Beans are the objects that are managed by Spring Framework’s Inversion of Control container. For example, Spring Bean is a building block that every Spring application needs. The Spring Bean acts like a helper that Spring automatically creates and manages. You do not have to create instances; you just tell the container what you need, and Spring will give it to you.

SCOPE

AVAILABILITY

INSTANCE COUNT

LIFETIME

USE

SINGLETON

Spring app

One per container

Created at startup, it lives until the container closes.

Stateless services, repositories, config holders—most of your beans

PROTOTYPE

Spring app

New one, whenever it is requested.

Spring creates it, gives it, and forgets it (no destroy callback). 

Beans that carry per-use state, e.g., a command or builder object

REQUEST

Web apps only 

Per HTTP request

Dies when the request finishes

Holding data tied to a single request, like a parsed form payload 

SESSION

Web apps only

Per HTP request

Dies when the session expires or is invalidated 

User preferences, shopping cart

APPLICATION

Web apps only 

One per Servlet context

available as long as the web application 

Data shared across every session in the

app 

WEBSOCKET

Web apps that are supported by WebSocket

One per websocket session

Dies when the socket closes

State for a single live connection


Every Spring Bean has singleton scope by default. That means every Spring Bean has one shared instance across the application. The singleton is efficient. The singleton works well for tasks. You can change the scope if you want to control how often new instances of a Spring Bean are created. Changing the scope helps manage memory, and changing the scope might change the behavior of a Spring Bean at times.

.15 Spring Boot Interview Questions and Answers updated for 2026: What is the Spring Framework?

 Want to ace your job interview? Start with these spring programming interview questions.

4. Difference between BeanFactory and ApplicationContext in Spring. 

 BeanFactory: This is Spring's basic container. It gives the simplest mechanism for managing beans (objects) and their life cycle. You can consider it to be the core bean manager.

1. ApplicationContext:

This is an advanced container built on top of BeanFactory. It manages beans and adds multiple enterprise-level features like event handling, internationalization, and automatic bean wiring.

2. Initialization:

 BeanFactory → Beans are instantiated in a lazy way (when you call getBean()).

ApplicationContext → Beans are instantiated eagerly (at startup), unless marked as lazy-init.

3. Features:

BeanFactory:

  • Simple bean instantiation and wiring.
  • It is used for smaller applications or memory-restricted devices.
  • ApplicationContext:
  • Everything that BeanFactory does, plus:
  • Event publication (ApplicationEventPublisher)
  • Internationalization (messages in different languages)
  • Annotation-based configurations
  • Automatic integration of BeanPostProcessor and BeanFactoryPostProcessor
  • Better integration with Spring's AOP, transaction management, and more.

4. Usage

 BeanFactory → Generally no longer used directly. Useful only in memory-constrained situations and needs to be extremely lightweight.

ApplicationContext → Generally needed in any modern Spring application (Spring Boot, Spring MVC, Spring Data, etc.). Practise these spring programming interview questions to build confidence.

Practice// Using BeanFactory

Resource resource = new ClassPathResource("beans.xml");

BeanFactory factory = new XmlBeanFactory(resource);

MyService service = (MyService) factory. getBean("myService");

 // Using ApplicationContext

ApplicationContext context =

 new ClassPathXmlApplicationContext("beans.xml");

MyService service2 = (MyService) context. getBean("myService");

5. What is the bean lifecycle in Spring? When are init/destroy callbacks used? 

 The Spring framework manages beans in Spring. They follow a lifecycle. This lifecycle starts when the Spring container creates the bean instance. This is called the instantiation phase.

The next lifecycle phase is dependency injection. Spring then connects the dependencies of the bean. The Spring container might also use processing logic with BeanPostProcessors before the initialization phase.

 The initialization phase is the next phase in the bean lifecycle. During the initialization phase, Spring calls init callbacks like @PostConstruct, afterPropertiesSet, or XML init methods.

Init methods are used for startup tasks like setting up connections, loading database configuration properties, getting data files, or initializing resources. Once an init method has been run, the bean enters the phase and is ready for the application to use.

At the point the application context is shutting down, the destruction phase begins. The destruction phase includes executing destroy callbacks to process other cleanup work to be done when the bean is taken out of service, such as closing connections to databases, shutting down threads, or clearing memory for other resources and/or releasing back to the JVM.

To summarize, the init callback methods prepare the bean and prepare any necessary business logic, and the destroy methods ensure safe cleanup after the bean is no longer being used.

6. How can beans be injected?

 There are possibly three ways in which beans can be injected:

  1. Constructor Injection
  2. Setter Injection
  3. Field Injection 

 Constructor Injection:

Dependencies are provided through a class constructor. This ensures the bean is fully initialized at creation. Example:

public class UserService {

 private final UserRepository repo;

 public UserService(UserRepository repo) { this. repo = repo; }

}

  Setter Injection:

Once the bean is created, the dependencies are given by setter methods. 

public void setRepo(UserRepository repo) { this. repo = repo; }

  Field Injection:

By using annotations like @Autowired, dependencies are immediately injected into class fields. It's more difficult to test.

In modern Spring applications, constructor injection is preferred for cleaner, testable, and immutable designs.

Understanding the answers to these spring programming interview questions can boost your chances.

7.How to find the ServletContext or ServletConfig in a Spring Bean? 

In the Spring application, it is possible by using Spring’s interfaces. If the bean needs access to the ServletContext, just make it implement the ServletContextAware interface. Spring will inject the ServletContext object when the bean is created. The same idea is used in ServletConfig. If the bean needs the ServletConfig, implement the ServletConfigAware interface. Spring will provide the ServletConfig object during initialization. Example:

 @Component

public class AppContextBean implements ServletContextAware {

 private ServletContext appContext;

  @Override

 public void setServletContext(ServletContext servletCtx) {

 this. appContext = servletCtx;

 }

}

8. How to retrieve ServletContext or ServletConfig in a Spring Bean?

 To access ServletContext or ServletConfig in a bean of a Spring application, you can use Spring's interfaces. Just implement the ServletContextAware interface. After that, Spring will give you access to the ServletContext once the bean is created. If you need to work with ServletConfig, use the ServletConfigAware interface.

@Component

 public class AppContextBean implements ServletContextAware {

 private ServletContext appContext;

  @Override

 public void setServletContext(ServletContext servletCtx) {

 this. appContext = servletCtx;

 }

}

 This approach allows you to retrieve context information like initialization parameters or application attributes. In modern applications, using these interfaces is the standard way to integrate traditional servlet-based resources with Spring beans.

9.What is view resolution, and how does Spring resolve views?

 View resolution is the step of Spring MVC. In the view resolution step the framework decides what the user will see on the screen. After the controller finishes processing, it returns a view name, like "profile" or "dashboard." The view name does not tell where the file is placed. That is where a ViewResolver becomes useful. The ViewResolver helps connect the view name to the file path.

 ViewResolver is a tool that takes a name and turns it into a real view resource. For example, if there is an InternalResourceViewResolver with a prefix of /WEB-INF/views/ and a suffix of.jsp then the logical name "dashboard" would be mapped to the file /WEB-INF/views/dashboard.jsp. This helps the system find the correct file to show the user.

10.Define Spring’s JdbcTemplate. What are its advantages?

 Spring’s JdbcTemplate is a helper class that simplifies database operations in Java. To start using plain JDBC requires a lot of repetitive code. Processes like opening/closing connections, creating statements, and handling exceptions are done by JdbcTemplate, which handles all this for you. Meanwhile, you can focus on writing SQL and mapping results. 

For example, to fetch all student names:

List names = jdbcTemplate.query(

 "SELECT name FROM students", 

 (rs, rowNum) -> rs.getString("name")

);

Advantages:

  • Reduces boilerplate code.
  • Handles exceptions automatically.
  • Supports safe parameterized queries.
  • Maps results easily to Java objects.
  • Supports batch operations.
  • Integrates seamlessly with Spring transactions.

 

Spring Programming Interview Questions (Intermediate)

1. What is Spring’s JdbcTemplate? State its advantages 

 JdbcTemplate is a Spring Framework tool that makes working with databases in Java simple. Using JDBC is boring and can lead to mistakes. You need to:

  1. Open connections
  2. Create statements
  3. Execute SQL
  4. Handle exceptions
  5. Close resources.

Imagine you have a student's table:

ID

Name

Age

1

Akaash

20

2

Rohan

22

To fetch all names:

@Autowired

private JdbcTemplate jdbcTemplate;

public List getAllStudentNames() {

 return jdbcTemplate. query(

"SELECT name FROM students,"

 (rs, rowNum) -> rs.getString("name")

 );

}

  Less boilerplate—fewer lines of repetitive code.

Automatic exception handling—converts SQLExceptions into Spring’s unchecked exceptions.

 Safe queries—supports parameterized queries to prevent SQL injection.

 Easy result mapping—maps rows to objects automatically.

 Batch operations—handles multiple inserts/updates efficiently.

Spring integration—works seamlessly with transactions.

2. How do you enable transactions in Spring? What are propagation behaviors and isolation levels?

In the Spring framework, transaction management starts by using the annotation on a method or a class. Tasks, like starting a transaction, committing a transaction, or rolling back a transaction, are handled by Spring. So that you do not need to worry about managing transaction control by yourself.

@Transactional

public void transfer Money(Account from, Account to, double amount) {

 withdraw(from, amount);

deposit(to, amount);

}

 Propagation Behaviors: Propagation is exactly how existing transactionality works while calling another transactional method. For example, REQUIRED will join an existing transaction, while REQUIRES_NEW will create a transaction.

 Isolation Levels: Isolation is how visible one transaction is to others, which prevents issues, like reads. Let's see an example: READ_COMMITTED means the transaction will only read values that are committed.

3. What is Spring DAO? How does Spring abstract database access/exception translation?

 I see that Spring DAO is a design pattern that separates database logic from business logic. I also see that Spring DAO offers a framework that lets developers implement DAO in a consistent manner.

 Database Access Abstraction

Spring abstracts JDBC and ORM frameworks through templates like JdbcTemplate or HibernateTemplate. You don’t write repetitive boilerplate code—Spring handles connections, statements, and result mapping.

Exception Translation

Spring converts checked SQLExceptions into unchecked, consistent exceptions like DataAccessException. This allows your code to handle database errors uniformly, without worrying about vendor-specific SQL codes.

Example:

try {

 jdbcTemplate.update("INSERT INTO students VALUES (?,?)", id, name);

} catch (DataAccessException e) {

 // Handle error uniformly

}

 Preparing for your Java developer role? Start with these spring programming interview questions to build a strong foundation.

4. What is AOP in Spring? What are Aspect, Advice, Pointcut, JoinPoint, and Weaving?

Sprint AOP means Aspect-Oriented Programming. AOP is a way of programming that keeps the part of the code separate from other tasks. The other tasks, called "cutting concerns," are things that appear in many places in an application. Typical cross‑cutting concerns are logging, security checks, transaction handling, and monitoring of performance. These cross-cutting concerns keep the core business rules neat. Make it easier to reuse parts of the code. An aspect is a module that contains cutting logic.

@Aspect

public class LoggingAspect { ... }

Advice – Code to execute at certain points in program flow:

Pointcut—Defines@Before("execution(* com.bank.service.*.*(..))")

public void logBefore(JoinPoint jp) {

 System.out.println("Executing: " + jp.getSignature());

}

 @Before—runs before method execution

@After—runs after method execution

@Around—runs before and after, can modify behavior. Pointcut—Defines where advice applies.

Example: all methods in the BankService class.

JoinPoint –

Represents a specific method execution or event in the application where advice runs.

Weaving –

Injecting aspects into the main code, done at runtime in Spring (using proxies).

5. Difference between Spring AOP and AspectJ.

Aspect

Spring AOP

AspectJ

Type

Proxy-based AOP: Uses Spring proxies for applying aspects at runtime

Full AOP framework: Supports compile-time, load-time, and runtime weaving.

Weaving

Only runtime weaving (via proxies)

Support for compile-time, load-time, and runtime weaving

Join Points

Method execution (limited)

Supports all join points: method calls, object construction, etc.

Performance

Some slight overhead due to proxies; acceptable for simple Spring applications.

More efficient for complex scenarios; can weave at compile-time.

Complexity

Easy to configure; works seamlessly for Spring apps

More complex; requires the AspectJ compiler or a load-time weaving setup.

 

Spring Programming Interview Questions (Advanced)

Spring Boot interview questions for 10 years of experience 

1. What is Spring Boot, and what are its Features?

 Spring Boot is a framework that follows a set of rules. It is built on top of the Spring framework. It helps create Java applications that are ready for use in production.

It eliminates boilerplate configurations, includes embedded servers, auto-configures application components, and allows programs to launch with the minimum configurations for independent programs to launch, without construction.

Main Features: 

Features                                                                Explanation

Auto-Configuration

Automatically sets up Spring components based on dependencies

Standalone Apps

Runs without external servers using embedded Tomcat/Jetty.

Starter POMs

Pre-packaged dependencies for web, JPA, security, etc.

Actuator

Provides endpoints for monitoring and health checks.

Externalized Configuration

Uses application. properties or YAML for environment-specific configs.

Example:

@SpringBootApplication

public class App {

 public static void main(String[] args) {

 SpringApplication.run(App.class, args);

 }

}

2. Difference between Spring and Spring Boot.

Feature

Spring

Spring Boot

Configuration

Requires manual XML or Java configuration for beans and dependencies 

Auto configures components with minimal setup.

Setup Complexity

Complex, needs an external server (Tomcat/Jetty) setup

Simple, including embedded servers and starter dependencies

Boilerplate code

High developers write repetitive code.

Low, reduces boilerplate with starters and defaults

Purpose

General-purpose framework for building java apps

Rapid development of production-ready standalone apps

Monitoring

Requires manual setup

Built-in actuator for health checks and metrics

3. What is an actuator in Spring Boot? Which endpoints are useful in production?

 Spring Boot Actuator is a tool that adds ready‑for‑production features to your application. Spring Boot Actuator supplies your application with monitoring, metrics, health checks, and management endpoints so developers can keep an eye on them. Control their application.

Useful Endpoints: 

  • /actuator/health:
    Shows app health (DB, disk, custom checks).
  • /actuator/metrics:
    Displays JVM, memory, and request metrics.
  • /actuator/info:
    Provides custom application info (version, build).
  • /actuator/env:
    Shows environment properties and configs.

Example: Access http://localhost:8080/actuator/health to check DB and app status instantly.

Spring programming interview questions are some of the most asked in Java interviews. This blog helps you understand and answer them confidently.

4. What embedded server(s) does Spring Boot support? How to change the default port or server?

 Spring Boot supports embedded web servers, so one should not use an external server. Tomcat (the default server), Jetty, and Undertow are the most widely supported.

Changing Default Server or Port: 

Task

Change Port:

Add server.port=9090 in application.properties or .yml.

Change Server:

Include starter dependency spring-boot-starter-jetty instead of spring-boot-starter-tomcat.

Example:

server.port=9090

  The app now runs on port 9090.

 Embedded server choice is automatic via dependencies.

5. What is Reactive Programming? What is Spring WebFlux? 

 Reactive programming is a way of writing code that does not wait for things to finish. It works by responding to data as soon as it arrives. This approach is great for apps that need to handle streams of data fast. Of waiting for actions to finish reactive programming acts right away when new data comes in. It is non-blocking, meaning it keeps working without getting stuck. This makes it efficient for handling amounts of information in real time.

  This allows for better scalability.

Spring WebFlux

Spring WebFlux is Spring’s reactive web framework, built on Project Reactor, for creating non-blocking REST APIs. It handles requests asynchronously and supports Reactive Streams.

Example:

@GetMapping("/numbers")

public Flux getNumbers() {

 return Flux.range(1, 5). delayElements(Duration.ofSeconds(1));

}

 Responds with numbers 1–5 without blocking threads.

 

Conclusion

By mastering the Spring Framework, new tech roles become available to you. Gaining experience with Spring Programming interview questions builds confidence and working skills.Sign up for Sprintzeal's Full Stack Developer Master Program Certification Training. You'll learn concepts through hands-on experience with Spring, Angular, Hibernate, and more, great preparation for Spring Programming interview questions.The course will follow a structure that includes both advanced topics. This will help you clearly explain your answers during interviews.

Stay consistent with training and practice the sample problems, and you too will start to see spring programming interview questions as a bridge to your success.

 

FAQs

1. What is a spring bean?

A spring bean is any object that Spring manages for you. Of writing new SomeClass yourself, you tell Spring what you need using annotations like Component or a Bean method. Spring then creates the object, sets up its dependencies, and gives it to whoever needs it.

2. What's the difference between singleton and prototype scope?

With singleton scope, there's one instance of the bean for the whole application. Every time it's needed, the same object is used. With prototype scope Spring creates an instance every time the bean is requested. Singleton is good for stateless beans. Saves memory. The prototype is for beans that need to keep their state per use.

3. Are request session and application scopes in a Java app

No. These scopes only work in web applications using Spring MVC or Spring WebFlux. They depend on HTTP requests and sessions. In a Java app without a web layer, Spring won't allow you to use these scopes because there's no request or session to tie them to

4. Why doesn't @PreDestroy get called on a prototype bean?

Because once Spring hands a prototype bean to you, it no longer owns it. For singleton beans, Spring keeps track of them. Can call cleanup methods like @PreDestroy when the application shuts down. With prototype beans, Spring doesn't keep a reference, so it can't call any destroy methods. You have to clean up the bean yourself.

5. Can you inject a prototype bean into a singleton bean?

You can. By default the singleton gets the prototype bean once. When it was first created. After that it keeps using the instance. That's usually not what you want. To get a prototype instance, you need to use a scoped proxy each time. ObjectFactory, ObjectProvider, or method injection

6. Is Spring singleton the same as the Singleton design pattern?

No. The classic Singleton design pattern makes sure there is one instance of a class in the JVM. Usually by using a constructor and a static method. Spring singleton means one instance per Spring container. If you have two ApplicationContext instances in the JVM, each gets its version of the bean. So it is not the same as the Singleton design pattern.

7. Which scope should I use by default?

Use singleton by default unless you have a reason not to. It's Springs' default because most beans, like service repositories and controllers, are stateless and can be shared safely. Use a prototype request or session when the bean needs to keep state that's tied to a use request or user session 

Written by

Mamatha J

Get Your Quote Today

Enter Your First Name
Enter Your Last Name
Enter a valid Email
Enter Your Phone Number
Select course

Download Blog Ebook

Download agenda

© 2026 Sprintzeal Americas Inc. - All Rights Reserved.

Disclaimer (Click Here)
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP and SP are registered marks of the Project Management Institute, Inc.
  • CBAP® - Is a registered trade mark of IIBA.
  • ITIL® is a registered trade mark of AXELOS Limited, used under permission of AXELOS Limited. The Swirl logoTM is a trademark of AXELOS Limited, used under permission of AXELOS Limited. All rights reserved
  • PRINCE2® is a registered trade mark of AXELOS Limited, used under permission of AXELOS Limited. The Swirl logoTM is a trademark of AXELOS Limited, used under permission of AXELOS Limited. All rights reserved
  • Certified ScrumMaster® (CSM) and Certified Scrum Trainer® (CST) are registered trademarks of SCRUM ALLIANCE®
  • Professional Scrum Master is a registered trademark of Scrum.org
  • The APMG-International Finance for Non-Financial Managers and Swirl Device logo is a trade mark of The APM Group Limited.
  • The Open Group®, TOGAF® are trademarks of The Open Group.
  • IIBA®, the IIBA® logo, BABOK® and Business Analysis Body of Knowledge® are registered trademarks owned by International Institute of Business Analysis.
  • CBAP® is a registered certification mark owned by International Institute of Business Analysis. Certified Business Analysis Professional, EEP and the EEP logo are trademarks owned by International Institute of Business Analysis..
  • COBIT® is a trademark of ISACA® registered in the United States and other countries.
  • CISA® is a Registered Trade Mark of the Information Systems Audit and Control Association (ISACA) and the IT Governance Institute.
  • CISSP® is a registered mark of The International Information Systems Security Certification Consortium ((ISC)2).
  • CompTIA A+, CompTIA Network+, CompTIA Security+ are registered marks of CompTIA Inc
  • CISCO®, CCNA®, and CCNP® are trademarks of Cisco and registered trademarks in the United States and certain other countries.
  • CSM®, CSPO®, CSD®, CSP®, A-CSPO®, A-CSM® are registered trademarks of Scrum Alliance®
  • TOGAF® is a registered trademark of The Open Group in the United States and other countries
  • All the online courses are accredited by respective governing bodies and belong to their respective owners.

Request a callback

Select valid Option
Enter Your First Name
Enter Your Last Name
Enter a valid Email
Enter Your Phone Number