Preparing for a Spring Boot interview or Java development role? This collection of Spring Boot MCQs is a practical resource for testing your knowledge of Spring Boot fundamentals, auto-configuration, dependency injection, REST APIs, validation, Spring Data JPA, transactions, security, Actuator, testing, caching, messaging, microservices, scheduling, deployment, and real-world Spring Boot scenarios.
Note: Score 60% or higher to unlock an exclusive offer of up to 50% off on self-paced Spring Boot courses.
Let’s begin!
1. What is Spring Boot primarily designed to do?
2. Which annotation is commonly used on a Spring Boot application entry class?
3. What does @SpringBootApplication combine?
4. What is Spring Boot auto-configuration intended to provide?
5. What is a Spring Boot starter?
6. Which embedded server is commonly used by Spring Boot web applications by default with the servlet stack?
7. What is the main benefit of an embedded server?
8. Which command commonly runs a Maven-based Spring Boot application?
9. What does SpringApplication.run typically do?
10. Which packaging style is commonly used for a deployable Spring Boot application?
11. Which file is commonly used for Spring Boot configuration in YAML format?
12. Which property sets the HTTP server port?
13. What is the purpose of application.properties?
14. What does Spring Boot support for externalized configuration?
15. What is a profile in Spring?
16. Which property activates a Spring profile?
17. What is @Value commonly used for?
18. What is @ConfigurationProperties useful for?
19. Why should secrets generally not be hard-coded in application.properties committed to source control?
20. What does configuration precedence help determine?
21. What is dependency injection?
22. What does IoC mean in Spring?
23. Which annotation commonly marks a class as a service component?
24. Which annotation commonly marks a repository component?
25. Which annotation is commonly used for a generic Spring-managed component?
26. What is constructor injection?
27. Why is constructor injection often preferred for required dependencies?
28. What happens when multiple beans match a dependency and no disambiguation exists?
29. Which annotation can designate a preferred bean when multiple candidates exist?
30. Which annotation can select a specific bean by qualifier?
31. What is a Spring bean?
32. What is the default Spring bean scope?
33. What does prototype scope mean?
34. Which annotation can define a bean-producing method inside a configuration class?
35. What is @PostConstruct commonly used for?
36. What is @PreDestroy commonly used for?
37. What does bean lazy initialization mean?
38. Which property enables lazy initialization globally?
39. What is a circular dependency?
40. Why can circular dependencies be problematic?
41. Which annotation is commonly used for a REST controller?
42. What does @GetMapping map?
43. What does @PostMapping map?
44. What does @PathVariable bind?
45. What does @RequestParam commonly bind?
46. What does @RequestBody typically do?
47. What does ResponseEntity allow a controller to control?
48. Which HTTP status commonly represents successful resource creation?
49. Which annotation can define a base path for controller methods?
50. What is content negotiation?
51. Which annotation is commonly used to validate a request object in a controller?
52. What is Bean Validation used for?
53. Which annotation commonly requires a string to contain non-whitespace characters?
54. Which annotation commonly requires a numeric value to be within a range?
55. What is @ControllerAdvice commonly used for?
56. What does @ExceptionHandler define?
57. What should a REST API generally return for malformed input?
58. Why use a consistent API error response format?
59. What is MethodArgumentNotValidException commonly associated with?
60. Why should stack traces generally not be returned directly to API clients in production?
61. What does Spring Data JPA primarily simplify?
62. Which annotation marks a JPA entity class?
63. Which annotation identifies an entity primary key?
64. What is JpaRepository commonly used for?
65. What is a derived query method?
66. What does @Query allow in a repository?
67. What is lazy fetching?
68. What is the N+1 query problem?
69. What does @Transactional provide?
70. Why can Open Session in View be controversial?
71. What is the main purpose of a database transaction?
72. What does transaction rollback do?
73. What does transaction propagation describe?
74. What does READ_COMMITTED isolation generally prevent?
75. What is a dirty read?
76. What is optimistic locking?
77. Which JPA annotation is commonly used for version-based optimistic locking?
78. What is pessimistic locking?
79. Why should transaction boundaries be chosen carefully?
80. What is a common reason a @Transactional method may not behave as expected when called from the same class?
81. What are authentication and authorization?
82. What is Spring Security primarily used for?
83. What is a SecurityFilterChain used for?
84. What is CSRF protection intended to mitigate?
85. When is CSRF protection especially relevant?
86. What is a PasswordEncoder used for?
87. Why should passwords not be stored as plaintext?
88. What is a JWT commonly used for?
89. What does method security control?
90. Why should authorization checks be enforced server-side?
91. What is Spring Boot Actuator?
92. Which endpoint commonly exposes application health information?
93. What is /actuator/info commonly used for?
94. Why should Actuator endpoints be secured?
95. What is Micrometer commonly used with Spring Boot for?
96. What is a liveness probe intended to indicate?
97. What is a readiness probe intended to indicate?
98. What is observability commonly composed of?
99. Why are correlation IDs useful?
100. What is a custom Actuator endpoint used for?
101. Which annotation is commonly used to load a full Spring Boot application context in a test?
102. What is a unit test generally intended to isolate?
103. What is @WebMvcTest commonly used for?
104. What is @DataJpaTest intended to focus on?
105. Why mock external services in many unit tests?
106. What is MockMvc used for?
107. What does an integration test generally verify?
108. Why use test-specific configuration?
109. What is Testcontainers useful for?
110. Why should integration tests avoid relying on shared mutable external state?
111. What is Spring Kafka commonly used for?
112. What is a Kafka topic?
113. What is a Kafka consumer group?
114. What is Spring AMQP commonly used for?
115. What is asynchronous processing useful for?
116. Which annotation can enable Spring asynchronous method execution?
117. Which annotation marks a method for asynchronous execution?
118. Why can message consumers need idempotency?
119. What is a dead-letter queue commonly used for?
120. What is event-driven architecture?
121. What is Spring Cloud commonly associated with?
122. What is service discovery?
123. What is an API gateway commonly responsible for?
124. What is a circuit breaker intended to do?
125. What is a timeout important for in distributed systems?
126. What is a retry storm?
127. Why use distributed tracing?
128. What is eventual consistency?
129. Why should distributed operations not assume a single local transaction covers every service?
130. What is a saga pattern used for?
131. What is a common way to containerize a Spring Boot application?
132. What is the purpose of a Dockerfile?
133. Why use environment variables in container deployments?
134. What is a Kubernetes readiness probe used for?
135. What is a Kubernetes liveness probe used for?
136. Why should container images be kept small?
137. What is a graceful shutdown?
138. Why is externalized configuration important in cloud deployments?
139. What is horizontal scaling?
140. What is a health check used for?
141. An API is returning database entities directly and exposing internal fields. What is a safer design?
142. A Spring Boot API becomes slow because a controller calls another service synchronously for every request. What should be investigated first?
143. A service occasionally fails when its database is unavailable. Which design helps it fail predictably?
144. Two beans implement the same interface and injection fails with an ambiguity error. What is a direct solution?
145. A REST endpoint performs a long-running report generation. What architecture can improve user experience?
146. A production application needs database credentials that differ by environment. What is appropriate?
147. A cache returns outdated product data after updates. What should be examined?
148. A controller has complex business logic and database calls. What refactoring is usually appropriate?
149. A Spring Boot application has slow startup because many beans are initialized but rarely used. Which feature may help?
150. A microservice repeatedly calls an unavailable dependency and overloads it further. Which pattern addresses this?