Spring Boot Interview Questions: What Interviewers Really Ask (With Scenarios)
By Preeti Verma
Spring Boot interviews reward people who know what happens behind the annotations. A lot of candidates can build a controller. Fewer can explain why their @Transactional method did not roll back. Here are the scenarios that come up most, with what a strong answer includes.
1. "Nothing rolled back"
Scenario: A method saves two records and the second insert fails, but the first is still in the database. What went wrong?
Points to make:
- @Transactional works through a proxy. The proxy starts and commits the transaction around your method call.
- If a method in the same class calls another @Transactional method directly (self-invocation), the call skips the proxy, so the annotation has no effect.
- The annotation does not work on private methods, because a proxy cannot intercept them.
- By default, rollback happens for unchecked exceptions. A checked exception commits unless you configure rollbackFor.
2. Circular dependencies
Scenario: Two beans depend on each other and the application fails at startup.
A circular dependency usually means two classes are doing too much. The best fix is to redesign: extract the shared part into a third class, or turn one dependency into an event. Workarounds exist (setter injection, @Lazy), but you should say they hide a design problem. Recent Spring Boot versions reject circular references by default, which is worth mentioning.
3. Bean scopes
Scenario: A bean holds per-user data and behaves strangely under load.
Beans are singletons by default, so one instance is shared by every request. Storing per-user state in a singleton is a bug. Explain the alternatives: request scope, session scope, prototype, or simply passing the data as method arguments. The last is usually the cleanest.
4. Handling exceptions in one place
Scenario: Every controller has its own try-catch and the API sometimes returns raw stack traces.
Answer with a global handler: a class annotated with @RestControllerAdvice and methods annotated with @ExceptionHandler that map exceptions to clear status codes and a consistent error body. Add that you never expose stack traces to clients and that you log the details on the server.
5. Auto-configuration
Scenario: A new joiner asks what Spring Boot actually adds over Spring.
Boot gives you starters (curated dependencies), auto-configuration (beans created based on what is on the classpath and in your properties), an embedded server and production features such as Actuator. Mention that auto-configuration backs off when you define your own bean, which is how you override it.
6. Actuator
Scenario: It is 2 a.m. and you need to know if a service is healthy.
Actuator exposes health, metrics and other endpoints. The important part of the answer is security: expose only what you need, put the rest behind authentication, and never leave sensitive endpoints open on a public port.
7. Configuration per environment
Scenario: The same build must run in development, test and production with different settings.
Use profiles and externalised configuration. Keep secrets out of the repository and read them from environment variables or a secrets manager. Say clearly that anything committed to git should be treated as public.
8. Securing an API with JWT
Scenario: You must secure a new REST API.
Walk through the flow: the user authenticates, the server issues a signed token, the client sends it on each request, and a filter validates the signature and expiry before the controller runs. Mention short expiry times, HTTPS only, and what you do about token revocation. For authorization, describe roles or permissions checked at the method or route level.
9. Connection pools
Scenario: Under load, the application runs out of database connections.
Spring Boot uses HikariCP by default. Talk about the maximum pool size, the connection timeout and what happens when threads wait for a connection. The insight interviewers like: making the pool bigger is not always the fix. Slow queries, long transactions and connections held during external calls are more common causes.
10. Testing
Scenario: Which annotations do you use to test a Spring Boot application?
Show that you choose the smallest test that answers the question: plain unit tests with Mockito for logic, slice tests such as @WebMvcTest or @DataJpaTest for one layer, and @SpringBootTest only when you need the full context. Candidates who say they "just use SpringBootTest for everything" often lose points because those tests are slow.
Practise the way it is asked
Try answering each scenario out loud in under a minute, then ask yourself the obvious follow-up. If you get stuck, the GenQuest AI Coach will explain the concept in simple words and let you ask why. Our Resources section has a large Core Java and backend question bank written in this scenario style, and our company-wise sheets collect the Spring Boot questions candidates report from real interviews.