πŸ†Spring Boot Interview Questions with Answers (200+ Questions)


Table of Contents
  1. Core Spring & Spring Boot Concepts
  2. Spring Boot Annotations & Configuration
  3. Dependency Injection & Bean Lifecycle
  4. Spring Boot Auto-Configuration & Starter Packs
  5. Spring Data JPA & Transactions
  6. Spring Boot REST APIs (Controllers, Validation, Exception Handling)
  7. Spring Security (OAuth2, JWT, Role-Based Access)
  8. Spring Boot with Microservices
  9. Spring Boot with Cloud & AWS
  10. Spring Boot Testing (JUnit5, Mockito, Integration Tests, Testcontainers)
  11. Spring Boot Actuator, Monitoring & Observability
  12. Conclusion

πŸ”Ή Core Spring & Spring Boot Concepts
  1. What is Spring Framework? How is it different from Spring Boot?
  2. Why was Spring Boot introduced? What problems does it solve?
  3. What are the advantages of using Spring Boot in enterprise applications?
  4. Explain the differences between Spring, Spring MVC, and Spring Boot.
  5. How does Spring Boot simplify dependency management?
  6. What is an embedded server in Spring Boot? Which servers are supported?
  7. Explain the concept of convention over configuration in Spring Boot.
  8. What are Spring Boot Starters? Give examples of commonly used ones.
  9. What are Spring Boot DevTools? Why are they used?
  10. How does Spring Boot differ from traditional WAR-based deployments?
  11. What is Spring Initializr and how does it help in project setup?
  12. What is the role of Spring Boot CLI? When is it useful?
  13. How does Spring Boot achieve auto-configuration?
  14. What are common Spring Boot application.properties and application.yml configurations?
  15. What is the difference between `application.properties` and `application.yml`?
  16. Explain Spring Boot’s layered architecture.
  17. What is the default logging framework used in Spring Boot?
  18. What are the limitations of Spring Boot?
  19. How do profiles work in Spring Boot?
  20. How do you override default properties in Spring Boot?

πŸ”Ή Spring Boot Annotations & Configuration
  1. What does the `@SpringBootApplication` annotation do internally?
  2. Difference between `@Component`, `@Service`, `@Repository`, and `@Controller`.
  3. Explain the use of `@Configuration` and `@Bean` annotations.
  4. What is the difference between `@ComponentScan` and `@EnableAutoConfiguration`?
  5. How does `@ConditionalOnProperty` work in Spring Boot?
  6. Explain the purpose of `@EnableConfigurationProperties` and `@ConfigurationProperties`.
  7. What is the difference between `@Value` and `@ConfigurationProperties`?
  8. How does Spring Boot handle externalized configuration?
  9. Explain `@Import` and when to use it.
  10. What does `@EnableScheduling` do? Provide an example.
  11. Difference between `@RestController` and `@Controller` in Spring Boot.
  12. What is the use of `@EnableAsync` in Spring Boot?
  13. Explain the `@Lazy` annotation in Spring.
  14. Difference between `@Primary` and `@Qualifier` annotations.
  15. What is the use of `@Profile` in Spring Boot?
  16. How does `@Scope` annotation work in Spring Boot?
  17. What is `@EnableTransactionManagement`?
  18. What is the role of `@PropertySource` annotation?
  19. What is the difference between `@ImportResource` and `@Import`?
  20. Explain `@EnableJpaRepositories` and its usage.

πŸ”Ή Dependency Injection & Bean Lifecycle
  1. What is Dependency Injection (DI) in Spring? Why is it important?
  2. What are the different types of Dependency Injection in Spring?
  3. What is the difference between constructor injection and setter injection?
  4. Which injection method is preferred in Spring and why?
  5. How does Spring manage the lifecycle of a bean?
  6. What is the role of the `BeanFactory` interface?
  7. Difference between `ApplicationContext` and `BeanFactory`.
  8. What are the different bean scopes available in Spring?
  9. How do you create a prototype-scoped bean?
  10. What is the default bean scope in Spring Boot?
  11. Explain the difference between singleton bean and prototype bean.
  12. What is the role of `@PostConstruct` and `@PreDestroy` annotations?
  13. How do you define custom initialization and destruction methods for beans?
  14. What are BeanPostProcessor and BeanFactoryPostProcessor?
  15. What is the difference between `@Autowired` and `@Inject`?
  16. What is circular dependency in Spring? How is it handled?
  17. Difference between field injection, setter injection, and constructor injection.
  18. What is `@DependsOn` annotation in Spring?
  19. How do you create lazy-initialized beans in Spring Boot?
  20. Explain the lifecycle phases of a Spring bean with example.

πŸ”Ή Spring Boot Auto-Configuration & Starter Packs
  1. What is auto-configuration in Spring Boot? How does it work?
  2. What is the role of `spring.factories` in auto-configuration?
  3. What is the difference between `@EnableAutoConfiguration` and `@SpringBootApplication`?
  4. How do you exclude an auto-configuration class in Spring Boot?
  5. What is the purpose of `META-INF/spring.factories` file?
  6. How do you create a custom auto-configuration in Spring Boot?
  7. What is the difference between `@ConditionalOnClass` and `@ConditionalOnMissingBean`?
  8. What is `@ConditionalOnProperty` and when would you use it?
  9. Explain `@ConditionalOnResource` and its use case.
  10. What are Spring Boot Starter dependencies?
  11. Give examples of commonly used Spring Boot Starter dependencies.
  12. How do Spring Boot Starters simplify dependency management?
  13. What is the difference between `spring-boot-starter-web` and `spring-boot-starter-webflux`?
  14. What is `spring-boot-starter-data-jpa` and what does it provide?
  15. Explain the role of `spring-boot-starter-security`.
  16. What is the purpose of `spring-boot-starter-test`?
  17. How do you create a custom Spring Boot Starter?
  18. What are the advantages of custom Spring Boot Starters?
  19. How do you debug issues with auto-configuration in Spring Boot?
  20. What is the role of `spring-boot-autoconfigure` module?

πŸ”Ή Spring Data JPA & Transactions
  1. What is Spring Data JPA and how is it different from Hibernate?
  2. What are the advantages of using Spring Data JPA?
  3. What is the role of `JpaRepository` interface?
  4. Difference between `CrudRepository`, `PagingAndSortingRepository`, and `JpaRepository`.
  5. How do you define custom query methods in Spring Data JPA?
  6. What is the difference between JPQL and native SQL queries?
  7. How do you use `@Query` annotation in Spring Data JPA?
  8. What is the difference between `getOne()` and `findById()`?
  9. Difference between `save()` and `saveAndFlush()`.
  10. What are derived query methods in Spring Data JPA?
  11. What is optimistic locking vs pessimistic locking in JPA?
  12. What is the role of `@Transactional` annotation in Spring Boot?
  13. Difference between declarative and programmatic transaction management.
  14. How do you configure transaction propagation in Spring?
  15. What is the difference between `REQUIRED`, `REQUIRES_NEW`, and `MANDATORY` propagation levels?
  16. What is the role of isolation levels in transactions?
  17. Explain `READ_COMMITTED`, `REPEATABLE_READ`, and `SERIALIZABLE` isolation levels.
  18. What is dirty read, non-repeatable read, and phantom read?
  19. How do you roll back transactions in Spring Boot?
  20. What is the difference between `rollbackFor` and `noRollbackFor` in `@Transactional`?

πŸ”Ή Spring Boot REST APIs (Controllers, Validation, Exception Handling)
  1. How do you create a REST API in Spring Boot?
  2. Difference between `@Controller` and `@RestController`.
  3. What is the role of `@RequestMapping` annotation?
  4. Difference between `@GetMapping`, `@PostMapping`, `@PutMapping`, `@DeleteMapping`, and `@PatchMapping`.
  5. How do you pass path variables in Spring Boot REST APIs?
  6. What is the difference between `@RequestParam` and `@PathVariable`?
  7. How do you send and receive JSON in Spring Boot?
  8. What is the role of `@RequestBody` annotation?
  9. What is the role of `@ResponseEntity`?
  10. How do you implement global exception handling in Spring Boot?
  11. What is the use of `@ControllerAdvice`?
  12. What is the difference between `@ExceptionHandler` and `@ControllerAdvice`?
  13. How do you perform input validation in Spring Boot?
  14. What is the role of `@Valid` and `@Validated` annotations?
  15. How do you define custom validation constraints?
  16. What is the difference between checked and unchecked exceptions in REST APIs?
  17. How do you implement versioning in REST APIs (URI, Query Params, Headers)?
  18. How do you implement HATEOAS in Spring Boot?
  19. How do you implement pagination and sorting in REST APIs?
  20. How do you secure REST APIs in Spring Boot?

πŸ”Ή Spring Security (OAuth2, JWT, Role-Based Access)
  1. What is Spring Security and why is it used?
  2. Difference between authentication and authorization.
  3. How do you configure basic authentication in Spring Boot?
  4. What is the role of `UserDetailsService` in Spring Security?
  5. What is the difference between `GrantedAuthority` and `Role`?
  6. How do you secure REST APIs with role-based access in Spring Boot?
  7. What is CSRF protection? How does Spring Security handle it?
  8. What is JWT (JSON Web Token)? How is it used in Spring Security?
  9. What are the advantages of JWT over session-based authentication?
  10. How do you implement JWT authentication in Spring Boot?
  11. What is the role of filters in Spring Security?
  12. Difference between `OncePerRequestFilter` and `GenericFilterBean`.
  13. What is OAuth2 and how does it work with Spring Security?
  14. Difference between OAuth2 authorization code flow, implicit flow, and client credentials flow.
  15. How do you implement OAuth2 login in Spring Boot?
  16. What is the difference between `@EnableWebSecurity` and `WebSecurityConfigurerAdapter`?
  17. How do you customize Spring Security configuration in Spring Boot 3.x (no `WebSecurityConfigurerAdapter`)?
  18. What is stateless authentication and why is it important for REST APIs?
  19. How do you secure endpoints with method-level security (`@PreAuthorize`, `@Secured`)?
  20. What is the difference between symmetric and asymmetric encryption in JWT?

πŸ”Ή Spring Boot with Microservices
  1. What are microservices and how are they different from monoliths?
  2. What are the main advantages of using microservices architecture?
  3. How do you implement service discovery using Eureka?
  4. What is the role of Netflix Eureka in Spring Cloud?
  5. How do you configure a Spring Boot application as a Eureka client?
  6. What is Spring Cloud Config Server? How is it used?
  7. How do you secure communication between Config Server and microservices?
  8. What is API Gateway? Difference between Zuul and Spring Cloud Gateway.
  9. How do you implement request routing with Spring Cloud Gateway?
  10. What is Feign Client and why is it used in microservices?
  11. Difference between Feign Client and RestTemplate.
  12. What is load balancing in microservices? How does Ribbon work?
  13. What is Resilience4j and how does it improve fault tolerance?
  14. Difference between Circuit Breaker, Bulkhead, Retry, and Rate Limiter patterns.
  15. How do you implement a circuit breaker in Spring Boot with Resilience4j?
  16. What is Hystrix? Why is Resilience4j preferred over Hystrix?
  17. What is distributed tracing? How do you implement it in Spring Boot?
  18. What are Sleuth and Zipkin? How do they work with Spring Boot?
  19. How do you handle centralized logging in microservices?
  20. What are the best practices for designing Spring Boot microservices?

πŸ”Ή Spring Boot with Cloud & AWS
  1. How do you deploy a Spring Boot application to AWS?
  2. What is the difference between AWS Elastic Beanstalk and ECS for Spring Boot apps?
  3. How do you connect a Spring Boot application to AWS RDS?
  4. What are the best practices for securing AWS RDS credentials in Spring Boot?
  5. How do you use AWS Parameter Store or Secrets Manager with Spring Boot?
  6. How do you integrate Spring Boot with AWS S3?
  7. How do you upload and download files to S3 using Spring Boot?
  8. What is the difference between S3 and EFS? When to use each?
  9. How do you integrate Spring Boot with AWS SQS?
  10. Difference between SQS standard and FIFO queues.
  11. How do you integrate Spring Boot with AWS SNS?
  12. What is the difference between SQS and SNS?
  13. How do you integrate Spring Boot with AWS Lambda?
  14. What are the best practices for building serverless applications with Spring Boot on AWS?
  15. How do you implement distributed caching with AWS ElastiCache (Redis/Memcached)?
  16. How do you configure Spring Boot for AWS DynamoDB?
  17. Difference between RDS and DynamoDB for Spring Boot apps.
  18. How do you secure Spring Boot applications running on AWS (IAM roles, VPCs, security groups)?
  19. What is AWS API Gateway and how do you integrate it with Spring Boot microservices?
  20. How do you monitor and scale Spring Boot microservices on AWS?

πŸ”Ή Spring Boot Testing (JUnit5, Mockito, Integration Tests, Testcontainers)
  1. What are the different types of testing in Spring Boot?
  2. Difference between unit test and integration test.
  3. How do you write a simple JUnit 5 test in Spring Boot?
  4. How do you mock dependencies using Mockito?
  5. Difference between `@Mock` and `@MockBean` in Spring Boot tests.
  6. What is the role of `@SpringBootTest` annotation?
  7. What is `@DataJpaTest` used for?
  8. How do you test REST controllers in Spring Boot?
  9. What is `MockMvc` and how is it used?
  10. Difference between `WebMvcTest` and `SpringBootTest`.
  11. How do you test service layer components?
  12. How do you test exception handling in Spring Boot?
  13. What are Testcontainers? Why are they useful?
  14. How do you use Testcontainers with Spring Boot?
  15. How do you test with an in-memory database like H2?
  16. What is the role of embedded Kafka/RabbitMQ in integration tests?
  17. How do you measure code coverage in Spring Boot tests?
  18. How do you test asynchronous methods in Spring Boot?
  19. How do you run Spring Boot tests in parallel?
  20. What are best practices for writing maintainable Spring Boot tests?

πŸ”Ή Spring Boot Actuator, Monitoring & Observability
  1. What is Spring Boot Actuator and why is it used?
  2. What are the default Actuator endpoints available in Spring Boot?
  3. How do you enable and secure Actuator endpoints?
  4. How do you create custom Actuator endpoints?
  5. What is Micrometer in Spring Boot?
  6. How do you integrate Spring Boot with Prometheus?
  7. How do you integrate Spring Boot with Grafana dashboards?
  8. How do you configure distributed tracing with Spring Cloud Sleuth?
  9. What is Zipkin and how does it integrate with Spring Boot?
  10. How do you send Spring Boot logs to ELK stack (Elasticsearch, Logstash, Kibana)?
  11. What are the best practices for monitoring microservices in production?
  12. What is health check endpoint and why is it important in cloud deployments?
  13. How do you configure metrics for JVM memory, threads, and garbage collection?
  14. How do you enable request/response tracing in Spring Boot?
  15. How do you integrate Spring Boot with centralized logging frameworks?
  16. What is OpenTelemetry and how does it relate to Spring Boot observability?
  17. How do you configure graceful shutdown in Spring Boot applications?
  18. What are performance tuning tips for Spring Boot in production?
  19. How do you handle thread pool tuning in Spring Boot?
  20. What are the common production pitfalls in Spring Boot and how to avoid them?

🏁 Conclusion

πŸ”₯ This compilation serves as a professional, structured, and comprehensive 200+ question Spring Boot interview preparation guide, ensuring complete coverage of critical areas:

This guide is designed as a master reference for Spring Boot interviews across startups, product-based firms, and enterprise companies. By practicing these questions, coding exercises, and real-world case studies, you will be fully prepared to tackle both conceptual and applied challenges in modern backend engineering interviews with confidence.