Top Spring Boot Interview Questions for 2–5 Years Experience (2025)
This guide is designed for developers with 2–5 years of Spring Boot experience. At this level, interviewers expect you to explain how things work internally, make design decisions, and handle real production issues.
- Spring Boot internals and architecture understanding
- REST API best practices and error handling
- Spring Data JPA, transactions, performance issues
- Security basics with real configuration
- Actuator, logging, and production readiness
1️⃣ Core Spring Boot Architecture
1. How does Spring Boot auto-configuration work internally?
Spring Boot scans AutoConfiguration classes listed in
META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports.
Each configuration class uses conditional annotations like:
@ConditionalOnClass@ConditionalOnBean@ConditionalOnProperty
Only when conditions match, beans are created. If you define your own bean, auto-configuration backs off.
2. What happens during Spring Boot application startup?
- Create
ApplicationContext - Load environment & properties
- Run auto-configurations
- Create beans and inject dependencies
- Start embedded web server
- Application becomes ready
You can hook into startup using ApplicationRunner or CommandLineRunner.
3. Difference between BeanFactory and ApplicationContext?
| BeanFactory | ApplicationContext |
|---|---|
| Lazy initialization | Eager initialization |
| Basic DI | DI + AOP + events + i18n |
| Lightweight | Enterprise-ready |
Spring Boot always uses ApplicationContext.
2️⃣ REST API Design & Error Handling
4. How do you design a clean REST API in Spring Boot?
- Use nouns, not verbs →
/api/users - Use HTTP methods properly (GET, POST, PUT, DELETE)
- Return correct HTTP status codes
- Use DTOs instead of entities
5. Why should we not expose JPA entities directly in APIs?
Reasons interviewers expect:
- Lazy-loading issues
- Security risk (exposing internal fields)
- Coupling API to DB structure
- Serialization problems (bi-directional mapping)
Best practice → Use DTOs.
6. How do you handle exceptions globally?
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(EntityNotFoundException.class)
public ResponseEntity<String> handleNotFound(Exception ex) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(ex.getMessage());
}
}
This keeps controllers clean and ensures consistent API responses.
7. Difference between Filter, Interceptor, and AOP?
| Filter | Interceptor | AOP |
|---|---|---|
| Servlet level | Spring MVC | Method level |
| Request/Response | Before/After controller | Cross-cutting logic |
| Auth, logging | Metrics, headers | Transactions, audit |
3️⃣ Spring Data JPA & Transactions
8. How does @Transactional work internally?
Spring creates a proxy around the bean. When a transactional method is called:
- Transaction begins
- Method executes
- Commit on success
- Rollback on RuntimeException
9. What is transaction propagation?
Defines how a method behaves when a transaction already exists.
- REQUIRED (default)
- REQUIRES_NEW
- MANDATORY
- SUPPORTS
For interviews, explain REQUIRED and REQUIRES_NEW clearly.
10. What is the N+1 problem and how do you solve it?
Occurs when one query loads entities and additional queries load each child entity.
Solutions:
- Use
JOIN FETCH - Use DTO projections
- Batch fetching
11. Optimistic vs Pessimistic locking?
| Optimistic | Pessimistic |
|---|---|
| Uses versioning | Uses DB locks |
| Better performance | Safer for high contention |
4️⃣ Security (Expected at 2–5 Years)
12. How does Spring Security work at a high level?
Spring Security uses a filter chain. Each request passes through multiple filters for authentication and authorization.
Request → Security Filters → Controller → Response
13. Stateless authentication using JWT?
- User logs in → JWT issued
- Client sends JWT in Authorization header
- Server validates token for every request
No session stored on server → scalable.
14. Difference between Role and Authority?
Authority is a permission, Role is a group of authorities.
Spring internally treats roles as authorities prefixed with ROLE_.
5️⃣ Actuator, Logging & Performance
15. Why is Spring Boot Actuator important?
It provides production-ready endpoints:
/actuator/health/actuator/metrics/actuator/info
Used heavily in monitoring tools like Prometheus and Kubernetes.
16. How do you secure Actuator endpoints?
- Expose only required endpoints
- Protect using Spring Security
- Never expose sensitive endpoints publicly
17. How do you improve performance in Spring Boot apps?
- Use pagination
- Avoid EAGER fetching
- Use caching (Redis)
- Optimize DB indexes
6️⃣ Testing & Deployment
18. Difference between unit test and integration test?
| Unit Test | Integration Test |
|---|---|
| Tests single class | Tests multiple components |
| Mocks dependencies | Uses real context |
19. What is Testcontainers and why use it?
Testcontainers runs real databases (Docker) during tests. It avoids “works on my machine” issues.
20. How do you deploy a Spring Boot app?
- Build fat JAR
- Run using
java -jar - Containerize using Docker
๐ผ Strengthen Your Spring Boot Interview Preparation
Interviews for developers with 2–5 years of experience focus on real-world Spring Boot usage — not just annotations. Deepen your preparation by mastering performance, JPA, REST APIs, threading, and scalability concepts.
⚡ High-Performance Spring Boot with Java 25
Learn how experienced developers design scalable and high-throughput Spring Boot systems.
๐ Spring Boot Performance Tuning & Optimization
Common interview discussions around latency, throughput, and JVM tuning.
๐ Spring Boot Threading & Async Execution
Understand thread pools, executors, and async execution in production apps.
๐ซ Blocking Calls & Scalability Issues
Interviewers frequently ask about blocking I/O and scalability bottlenecks.
๐️ Spring Boot Database Performance Tuning
Learn how JPA, JDBC, and connection pools impact performance in real applications.
๐ Spring Boot JPA Basics
Revisit JPA fundamentals often questioned even at mid-level interviews.
๐งพ REST API Validation Annotations
Validation strategies are commonly discussed in REST-focused interviews.
✅ Custom Validation Annotations
Demonstrate clean code practices by building reusable validators.
๐จ Global Exception Handling
Handling errors consistently is a common real-world interview scenario.
๐️ Java System Design Interview Questions
Transition from Spring Boot internals to system-level architecture discussions.