Top Spring Boot Interview Questions for 2–5 Years Experience (2025)

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.

This article focuses on:
  • 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.

Interviewers expect you to say: “Auto-configuration is condition-based and non-invasive.”

2. What happens during Spring Boot application startup?

  1. Create ApplicationContext
  2. Load environment & properties
  3. Run auto-configurations
  4. Create beans and inject dependencies
  5. Start embedded web server
  6. Application becomes ready

You can hook into startup using ApplicationRunner or CommandLineRunner.


3. Difference between BeanFactory and ApplicationContext?

BeanFactoryApplicationContext
Lazy initializationEager initialization
Basic DIDI + AOP + events + i18n
LightweightEnterprise-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?

FilterInterceptorAOP
Servlet levelSpring MVCMethod level
Request/ResponseBefore/After controllerCross-cutting logic
Auth, loggingMetrics, headersTransactions, 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
Calling a @Transactional method inside the same class will NOT start a transaction.

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?

OptimisticPessimistic
Uses versioningUses DB locks
Better performanceSafer 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 TestIntegration Test
Tests single classTests multiple components
Mocks dependenciesUses 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
At 2–5 years level, interviewers want to see that you understand why decisions are made, not just annotations.

๐Ÿ’ผ 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.