Spring Boot interview questions 2026 - code on a developer monitor
Photo via Unsplash

Spring Boot Interview Questions: 2026 Guide

Spring Boot remains the default stack for Java backend roles, which means almost every Java interview in 2026 includes a Spring Boot round. The bar has moved, though. Interviewers rarely ask you to recite what an annotation does. They want to know why the framework behaves the way it does, where it breaks in production, and how you would debug it. This guide covers the Spring Boot interview questions that actually come up, with the reasoning a strong candidate gives.

Why Spring Boot Interviews Feel Harder in 2026

Most teams now run Spring Boot 3.x or 4.x on Java 17 or 21, with Jakarta EE namespaces, native observability through Micrometer, and optional virtual threads. Candidates who learned Spring from older tutorials often stumble on these changes. Expect a mix of fundamentals (dependency injection, auto-configuration), data access (JPA and transactions), and production concerns (Actuator, resilience, testing).

Core Spring Boot Interview Questions

1. How does auto-configuration actually work?

@SpringBootApplication combines @Configuration, @ComponentScan and @EnableAutoConfiguration. The last one loads candidate configuration classes listed in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports inside each starter jar. Each class is guarded by conditions such as @ConditionalOnClass, @ConditionalOnProperty and @ConditionalOnMissingBean.

The key insight interviewers look for: auto-configuration backs off. If you define your own DataSource or ObjectMapper bean, @ConditionalOnMissingBean makes Boot skip its default. Mention that you can debug decisions with --debug (the condition evaluation report) or the Actuator /actuator/conditions endpoint.

2. What is a starter, and when would you write your own?

A starter is a dependency descriptor that pulls in a curated set of libraries plus their auto-configuration. Writing a custom starter makes sense when several internal services share cross-cutting setup, such as a standard audit logger or a company-wide HTTP client with tracing and retries. Senior candidates mention splitting it into an autoconfigure module and a thin starter module.

3. Constructor, setter or field injection?

Prefer constructor injection. It makes dependencies explicit, supports final fields, works without a Spring context in unit tests, and surfaces circular dependencies at startup. Since Spring Boot 2.6, circular references are prohibited by default, which is usually a sign the design needs a third collaborator or an event.

Transactions and Proxies: The Classic Trap

If an interviewer asks one tricky question, it is usually this one: why does @Transactional sometimes do nothing?

@Service
public class OrderService {

    public void placeOrders(List<Order> orders) {
        orders.forEach(this::saveOrder); // self-invocation: no proxy, no transaction
    }

    @Transactional
    public void saveOrder(Order order) {
        repository.save(order);
        inventoryClient.reserve(order);
    }
}

Spring applies @Transactional through a proxy. A call from inside the same bean (this.saveOrder) bypasses the proxy, so no transaction starts. The same applies to @Async and @Cacheable. Fixes include moving the method to another bean, annotating the outer method, or using TransactionTemplate for explicit control.

Follow-ups you should be ready for:

  • Rollback rules: by default only unchecked exceptions and errors trigger rollback. Checked exceptions need rollbackFor.
  • Propagation: REQUIRED joins an existing transaction; REQUIRES_NEW suspends it and opens a new one, useful for audit logs that must persist even if the main work fails.
  • Private methods: annotations on private methods are ignored by proxy-based AOP.
  • Remote calls inside transactions: holding a database connection while waiting on an HTTP call is a common cause of pool exhaustion.
Server racks representing Spring Boot microservices in production
Photo via Unsplash

Spring Data JPA Questions

4. What is the N+1 problem and how do you fix it?

Loading a list of parents and then lazily touching a collection on each one triggers one query for the list plus one query per row. Fixes include a JOIN FETCH query, an @EntityGraph on the repository method, batch fetching (hibernate.default_batch_fetch_size), or a DTO projection when you only need a few columns. Strong answers mention how you detected it: SQL logging, Hibernate statistics, or query counts in integration tests.

5. Should you disable open-in-view?

Spring Boot enables spring.jpa.open-in-view by default and logs a warning about it. It keeps the persistence context open through view rendering, which hides lazy-loading bugs and holds connections longer. Most production teams set it to false and fetch what they need in the service layer.

6. When would you skip JPA entirely?

For reporting queries, bulk updates or heavy read paths, plain JdbcClient or a projection is often clearer and faster. Interviewers like candidates who choose tools by workload instead of defaulting to entities everywhere.

REST APIs, Validation and Error Handling

Expect questions on building clean APIs. Know how @RestControllerAdvice centralises exception handling and how Spring 6+ supports RFC 9457 ProblemDetail responses out of the box:

@RestControllerAdvice
public class ApiErrors {

    @ExceptionHandler(OrderNotFoundException.class)
    ProblemDetail handleNotFound(OrderNotFoundException ex) {
        ProblemDetail pd = ProblemDetail.forStatus(HttpStatus.NOT_FOUND);
        pd.setTitle("Order not found");
        pd.setDetail(ex.getMessage());
        return pd;
    }
}

Pair this with Bean Validation (@Valid, @NotBlank, custom constraints) and be able to explain the difference between a validation failure (400) and a business rule violation (often 409 or 422).

Engineers discussing Spring Boot design trade-offs in an interview
Photo via Unsplash

Production-Readiness and Microservices Questions

For mid-level and senior roles, this section often decides the outcome.

  • Actuator and probes: explain /actuator/health liveness and readiness groups and why a failing downstream dependency should usually affect readiness, not liveness.
  • Configuration: property precedence, profiles, @ConfigurationProperties with validation, and keeping secrets out of the jar.
  • Observability: Micrometer metrics and tracing, correlation IDs in logs, and what you would alert on (latency percentiles, error rate, saturation).
  • Resilience: timeouts first, then retries with backoff, circuit breakers (for example Resilience4j), and bulkheads. Retries without timeouts or idempotency are a red flag.
  • Virtual threads: setting spring.threads.virtual.enabled=true on Java 21 lets blocking I/O scale without reactive code, but you still need connection-pool limits and should watch for pinning in older libraries.
  • Graceful shutdown: server.shutdown=graceful plus a sensible timeout so in-flight requests finish during rolling deploys.

Testing Questions Interviewers Love

Know when to use each test style:

  • Plain unit tests for services, thanks to constructor injection and mocks.
  • Slice tests such as @WebMvcTest and @DataJpaTest load only the relevant layer and run much faster than a full context.
  • @SpringBootTest with Testcontainers for real database and broker behaviour. Mention @ServiceConnection, which wires container connection details automatically.

A good follow-up point: too many distinct @MockBean or @MockitoBean combinations break context caching and slow the suite dramatically.

Developer practising Spring Boot interview questions on a laptop
Photo via Unsplash

A Two-Week Spring Boot Interview Prep Plan

  1. Days 1-3: Build a small service from scratch: REST endpoints, validation, ProblemDetail errors, and a Postgres repository.
  2. Days 4-6: Break it on purpose. Reproduce the self-invocation bug, an N+1 query and a lazy-loading exception, then fix each one.
  3. Days 7-9: Add Actuator, Micrometer metrics, timeouts and a circuit breaker around an external call.
  4. Days 10-11: Write slice tests and one Testcontainers integration test.
  5. Days 12-14: Run mock interviews. Explain each design choice out loud in under two minutes, including the trade-off you rejected.

Interviewers trust candidates who can say “here is the bug I hit, here is how I found it, and here is what I changed.” Hands-on stories beat memorised definitions every time.

Start Preparing Today

Spring Boot interviews reward depth over breadth. Pick three areas from this guide where your explanation feels shaky, build a tiny project that exercises them, and practise answering out loud this week. If you want structured mock interview practice alongside your prep, try Niraswa AI. Start today, and walk into your next Java backend interview ready to explain not just what Spring does, but why.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *