Spring Framework Interview Questions
IoC, dependency injection, Spring Boot, beans, and common annotations.
- 20Questions with answers
- 3Difficulty levels
Questions (20)
Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.
What is the Spring Framework?
Spring is a lightweight Java framework that provides infrastructure support for developing enterprise applications.
What are the advantages of Spring?
Spring provides dependency injection, loose coupling, modular architecture, transaction management, security integration, and easier testing.
What is IoC (Inversion of Control)?
IoC is a principle where the framework manages object creation and dependency management instead of application code.
What is Dependency Injection in Spring?
Dependency Injection is the process of supplying dependencies to objects through constructors, setters, or fields.
What are the types of Dependency Injection?
The main types are Constructor Injection, Setter Injection, and Field Injection.
What is a Spring Bean?
A Spring Bean is an object that is instantiated, configured, and managed by the Spring IoC container.
What is the Bean Lifecycle in Spring?
The Bean Lifecycle includes instantiation, dependency injection, initialization, usage, and destruction.
What is Spring Boot?
Spring Boot is an extension of Spring that simplifies application setup through auto-configuration and starter dependencies.
What is the difference between Spring and Spring Boot?
Spring requires more manual configuration, while Spring Boot provides auto-configuration and embedded servers for rapid development.
What does @Autowired do?
@Autowired automatically injects dependencies managed by the Spring container.
What is @Component?
@Component marks a class as a Spring-managed bean for component scanning.
What is @Service?
@Service is a specialization of @Component used for service-layer classes.
What is @Repository?
@Repository is used for persistence-layer classes and enables exception translation.
What is @RestController?
@RestController combines @Controller and @ResponseBody to create RESTful web services.
What are Spring Boot Starters?
Spring Boot Starters are dependency descriptors that simplify project configuration by bundling commonly used libraries.
Which Java language or JDK features are essential when discussing Spring Framework?
Name concrete APIs (collections, concurrency, streams, annotations) tied to Spring Framework. Interviewers want syntax-level clarity plus when you would reach for each feature in production.
How does exception handling typically work around Spring Framework in Java?
Prefer specific checked/unchecked exceptions, wrap lower-level failures with context, and avoid empty catch blocks. For Spring Framework, decide what is recoverable vs fatal to the request thread.
What unit-testing approach would you use for Spring Framework?
JUnit 5 with Arrange-Act-Assert, Mockito for collaborators, and parameterized tests for edge cases. Keep Spring Framework logic pure where possible so tests stay fast.
How do equals/hashCode or identity rules affect Spring Framework?
Incorrect equals/hashCode break HashMap/HashSet behavior. If Spring Framework stores objects in collections, explain the contract and mutability pitfalls.
What memory or GC concern should juniors watch with Spring Framework?
Retain only needed references, prefer streaming for large datasets, and avoid accidental caches. Relate leaks or GC pressure to a concrete Spring Framework scenario.
Practice with AI mock interviews
Run Java mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.
Free to start · No credit card required