100 scenario-based Spring Boot & related questions
Spring Boot Spring MVC
Spring Data Spring Security
Spring Cloud Microservices
Kafka Rest API
1. You need to create a REST API quickly. Why would you choose Spring Boot over
traditional Spring?
2. How does Spring Boot reduce boilerplate code? Give a practical example.
3. What is the purpose of @SpringBootApplication annotation in a Spring Boot project?
4. Suppose your application is not picking up application.properties. What could be the
cause?
5. How do you externalize configuration in Spring Boot and manage environments like
dev/prod?
6. Your REST API should return a custom error message when validation fails. How
would you achieve that?
7. How can you run specific logic right after Spring Boot application startup?
8. How do you disable a specific auto-configuration class?
9. Your service needs to schedule a job every 5 minutes. How would you implement this
in Spring Boot?
10. Explain a situation where you would override a Spring Boot auto-configuration.
11. How do you inject values from a properties file into a Spring Boot bean?
12. How would you implement application versioning in a Spring Boot API?
13. How would you monitor a Spring Boot application in production?
14. How would you expose custom metrics in Spring Boot?
15. You want to deploy a Spring Boot application to Docker. What steps would you take?
16. You want to change the default port of your Spring Boot app. How would you do
that?
17. How would you set different logging levels for specific packages in Spring Boot?
18. Your app fails to start due to a circular dependency. How would you resolve it?
19. How do you create a custom starter in Spring Boot?
20. You want to integrate Swagger UI into your Spring Boot application. How would you
proceed?
21. How do you configure Spring Boot to connect to multiple databases?
22. Explain how CommandLineRunner and ApplicationRunner are used in real projects.
23. You have a long-running process. How do you ensure it doesn't block the main thread
in Spring Boot?
24. What are profiles in Spring Boot and how do you load different configs per profile?
25. How would you handle application-level exceptions uniformly in a Spring Boot app?
26. You want to build a REST endpoint to return a list of products. What annotations
would you use?
27. Your controller is returning plain JSON instead of a view. What could be wrong?
28. How would you handle file uploads in a Spring Boot REST controller?
29. How can you implement API versioning in Spring MVC?
30. How would you create a global exception handler in a Spring Boot REST API?
31. How do you handle 404 errors for non-existent endpoints?
32. You want to validate incoming JSON request payloads. How would you do that?
33. How do you ensure thread safety in Spring MVC controllers?
34. How would you customize the JSON response using Jackson annotations?
35. What’s the difference between @RequestParam, @PathVariable, and
@RequestBody?
36. How would you secure a specific endpoint to be accessible by only admin users?
37. How do you stream a large file download using Spring MVC?
38. How can you return a custom HTTP status code with a REST response?
39. How would you write integration tests for your controller using MockMvc?
40. How can you return paginated results from a REST API?
41. You want to create a repository to interact with a Customer entity. How would you
define it?
42. What’s the difference between CrudRepository, JpaRepository, and
PagingAndSortingRepository?
43. How do you create a custom query using JPQL or native SQL?
44. How would you implement a one-to-many relationship using Spring Data JPA?
45. Suppose you need to fetch data from two tables. How would you write a custom join
query?
46. How do you prevent the N+1 select problem in JPA?
47. What is optimistic locking and how would you implement it?
48. How do you handle lazy loading exceptions in a REST controller?
49. How would you batch insert or update entities using Spring Data JPA?
50. What’s the impact of @Transactional(readOnly = true) in a method?
51. How would you audit entity creation and update times automatically?
52. Explain a scenario where you would use entity listeners in JPA.
53. How can you implement soft deletes using Spring Data JPA?
54. How would you write a dynamic query using Specification or CriteriaBuilder?
55. How do you handle database connection pooling in Spring Boot?
56. How would you secure REST endpoints using Spring Security?
57. You want to secure an endpoint with roles. How would you do that in Spring
Security?
58. What’s the difference between @PreAuthorize and @Secured?
59. How do you configure JWT authentication in a Spring Boot REST API?
60. You want to allow CORS for specific origins only. How would you implement this?
61. How do you store passwords securely in Spring Security?
62. How do you implement custom authentication logic?
63. How can you use OAuth2 with Spring Boot for social login?
64. What are security filters and how can you add a custom one?
65. How would you handle CSRF protection in a stateless REST API?
66. You want your microservices to register themselves and discover each other. What
would you use?
67. How do you implement load balancing between microservices using Spring Cloud?
68. How would you externalize configuration across services using Spring Cloud Config?
69. How do you secure communication between microservices?
70. What is the role of an API Gateway in a Spring Cloud setup?
71. How would you implement circuit breaker functionality?
72. What’s the use of FeignClient and when would you prefer it over RestTemplate?
73. Your config server is down. How do you make your services resilient?
74. What is service discovery and how does Eureka support it?
75. How do you refresh properties at runtime using Spring Cloud Config?
76. How do you implement rate limiting in Spring Cloud Gateway?
77. How do you implement a fallback method for a failing service using Resilience4j?
78. How do you monitor distributed tracing in microservices?
79. How would you implement centralized logging in Spring Boot microservices?
80. How do you deploy multiple microservices using Docker Compose?
81. What’s the role of Sleuth and Zipkin in Spring Cloud?
82. How would you use Spring Cloud Bus to refresh configurations?
83. How do you implement retry logic when calling a dependent service?
84. How do you handle versioning in microservices?
85. How would you implement token propagation across microservices?
86. How do you integrate Swagger/OpenAPI with Spring Boot?
87. How do you document an API that takes a file upload using Swagger?
88. How do you write unit tests for service layer classes using Mockito?
89. How do you write integration tests for a REST API?
90. What’s the difference between @Mock, @Spy, and @InjectMocks?
91. How would you mock a repository call using Mockito?
92. How would you test an endpoint that returns paginated data?
93. What’s the difference between WebMvcTest and SpringBootTest?
94. You want to consume messages from a Kafka topic. How would you configure your
Spring Boot app?
95. How would you produce and consume JSON payloads in Kafka using Spring Kafka?
96. How do you ensure message ordering in Kafka consumer logic?
97. How would you handle failed Kafka messages? (e.g., retries or dead-letter topic)
98. How do you monitor Kafka consumer lags in a Spring Boot application?
99. How do you write test cases for Kafka consumers and producers?
100. How would you secure a Kafka topic in a microservices environment?