---
title: "Spring Boot Interview Questions, Answered With What Breaks in Production"
description: "Thirteen questions built around the failures: why @Transactional silently does nothing, why your connection pool should be smaller than you think, and what the condition evaluation report tells you."
canonical_url: https://devprep.co/articles/spring-boot-interview-questions
md_url: https://devprep.co/articles/spring-boot-interview-questions.md
last_updated: 2026-11-19
access: public
---

# Spring Boot Interview Questions, Answered With What Breaks in Production

> [!NOTE]
> The short answer
>
> Spring Boot interviews punish people who learned the annotations without learning what they expand into. Almost every hard question in this article is the same question in disguise: what did the framework do on your behalf, and what happens when its assumption is wrong?

Spring Boot is the most-used Java application framework, and the interviews reflect that: they are less about whether you can start an application and more about whether you can explain one that is misbehaving. The annotations are easy. Knowing that `@Transactional` silently does nothing when you call the method from inside the same class is the part that gets tested.

What follows is ordered the way a real loop goes. The early questions are answerable after a few months with the framework. The later ones are the ones that decide senior and staff offers.

## Fundamentals

### 1. What does `@SpringBootApplication` actually do?

It is three annotations in one, and naming them is the answer:

- `@SpringBootConfiguration` marks the class as a source of bean definitions.
- `@ComponentScan` scans the current package and everything below it.
- `@EnableAutoConfiguration` turns on the conditional configuration that gives Boot its name.

The second one has a consequence worth stating, because it is a real bug people hit: component scanning starts at the annotated class's package. Put your main class in `com.example.app.boot` while your services live in `com.example.app.service`, and nothing is found. The convention of putting the main class in the root package is not style, it is load-bearing.

### 2. How does auto-configuration decide what to configure?

By conditions, evaluated at startup. Each auto-configuration class is annotated with things like `@ConditionalOnClass`, `@ConditionalOnMissingBean` and `@ConditionalOnProperty`. Boot asks: is this class on the classpath, and has the application already defined this bean itself?

`@ConditionalOnMissingBean` is the one to understand, because it explains the whole design. Auto-configuration backs off whenever you have configured something yourself. That is why adding your own `DataSource` bean quietly disables Boot's, with no error and no warning.

> [!TIP]
> The answer that separates candidates
>
> Say how you would _debug_ it, not just how it works. Run the application with `--debug` and Boot prints a condition evaluation report: every auto-configuration it applied, every one it skipped, and the condition that decided. "I would read the condition evaluation report" is a much better answer than any description of the mechanism, because it shows you have had to find out why a bean was missing at four in the afternoon.

### 3. Constructor injection or field injection?

Constructor, and the reasons are concrete rather than stylistic.

```java
// Field injection. Compiles. Starts. Hides two problems.
@Service
public class OrderService {
    @Autowired private PaymentClient payments;   // cannot be final
    @Autowired private InventoryClient inventory; // invisible to a plain `new`
}

// Constructor injection. The dependencies are part of the type.
@Service
public class OrderService {
    private final PaymentClient payments;
    private final InventoryClient inventory;

    OrderService(PaymentClient payments, InventoryClient inventory) {
        this.payments = payments;
        this.inventory = inventory;
    }
}
```

Constructor injection makes the fields `final`, so the object cannot exist half-built. It makes the dependencies visible in the signature, so a class quietly accumulating eight collaborators becomes obvious rather than hidden behind annotations. And it lets a unit test construct the class with plain `new`, no Spring context at all, which is usually the fastest test you can write.

A class with a single constructor needs no `@Autowired` at all; Spring has inferred it for years.

### 4. `@Component` or `@Bean`?

`@Component` for classes you own, found by scanning. `@Bean` inside a `@Configuration` class for things you cannot annotate: a third-party client, an object needing construction logic, or several instances of the same type distinguished by name.

## Data access, where most production incidents start

### 5. Why does `@Transactional` sometimes do nothing?

This is the most reliable senior-level Spring question, because the failure is silent.

```java
@Service
public class ReportService {

    public void generateAll(List<Long> ids) {
        for (Long id : ids) {
            generateOne(id);   // NOT transactional. No proxy involved.
        }
    }

    @Transactional
    public void generateOne(Long id) { /* ... */ }
}
```

Spring implements `@Transactional` with a proxy. Callers outside the bean go through the proxy and get a transaction; a call from inside the same object is a plain Java method call on `this`, which never touches the proxy. The annotation is still there, and it does nothing. The [Spring Framework reference](https://docs.spring.io/spring-framework/reference/data-access/transaction/declarative/annotations.html) states this directly, and it still catches people every year.

Two more parts of the same question, both worth volunteering: proxied methods must be public, and by default Spring rolls back on unchecked exceptions only. Throw a checked exception and the transaction commits unless you set `rollbackFor`. Saying that unprompted is a strong signal.

### 6. What is the N+1 query problem and how do you find it?

You fetch 50 orders with one query, then touch `order.getCustomer()` on each, and the lazy proxy fires a query per order. Fifty-one queries where two would do. It does not show up in tests with three rows; it shows up as a slow endpoint in production.

```java
// The fix: tell the query what you will need.
@Query("select o from Order o join fetch o.customer where o.status = :status")
List<Order> findByStatusWithCustomer(@Param("status") OrderStatus status);
```

The better half of the answer is detection. Set `spring.jpa.show-sql` in development, or add a datasource proxy that counts queries per request and fails a test above a threshold. An interviewer asking this question usually wants to hear that you would catch it automatically rather than by reading logs.

### 7. How big should the connection pool be?

Smaller than people guess. The instinct is "we have 200 concurrent requests, so 200 connections", and that is backwards: each connection costs memory and a backend process on the database, and past a point more connections make throughput worse, not better.

HikariCP, the pool Boot ships with, publishes a [pool sizing guide](https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-Sizing) arguing that a small, fixed pool outperforms a large one, because the database can only execute so much in parallel and queuing in the application is cheaper than thrashing in the database.

```diagram
direction: lr
width: 700
caption: Where the ceiling actually is. Adding connections past the database's parallel capacity moves the queue, it does not remove it.

nodes:
  - { id: req, label: Requests,   note: 200 concurrent }
  - { id: pool, label: Hikari pool, note: 10 connections, style: accent }
  - { id: db,  label: Postgres,   note: max_connections, style: store }
  - { id: cpu, label: Real limit, note: cores and disk, style: warn }

edges:
  - [req, pool, "wait here"]
  - [pool, db, "10 in flight", hot]
  - [db, cpu, "bounded by", hot]
```

The answer that lands: name the real constraint, say you would measure rather than guess, and point out that a pool larger than the database's `max_connections` divided by the number of application instances is a connection-refused incident waiting for a deploy.

## Configuration and operations

### 8. Where does configuration come from, and who wins?

Spring Boot reads from many sources and applies a defined precedence. Command-line arguments beat environment variables, which beat profile-specific files, which beat `application.properties`, which beats defaults in code. The full ordering is in the [externalized configuration reference](https://docs.spring.io/spring-boot/reference/features/external-config.html).

The practical consequence interviewers want: you do not need to rebuild an image to change a setting per environment, and a value that "will not take effect" is almost always being overridden by something higher in that list.

### 9. What belongs in Actuator, and what must never be public?

Actuator gives you health, metrics, environment and thread dumps over HTTP. Health is the one you expose to a load balancer. Almost everything else leaks: `/env` shows configuration, `/heapdump` hands over memory, `/mappings` enumerates your routes.

The answer is to expose them on a separate management port, bound to the internal network, and to secure them. Saying "I would expose only health and expose the rest on a port the internet cannot reach" is the whole answer.

### 10. How do you keep startup from being slow?

Know where the time goes before optimising it. Component scanning across a broad package tree, eager initialisation of beans nothing uses, and database migrations running in-process all cost seconds. Lazy initialisation trades startup time for first-request latency, which is the wrong trade for a service behind a load balancer and the right one for a short-lived job.

## Questions for senior and staff candidates

### 11. When would you choose WebFlux over MVC?

Rarely, and being able to say that is the point. WebFlux pays off when a service is IO-bound and fans out to many slow downstreams, where blocking a thread per request is the bottleneck. It costs you a reactive programming model that most teams debug badly, and a single blocking call anywhere in the chain erases the benefit while making it harder to find.

Since virtual threads landed in Java, the usual reason to reach for WebFlux got weaker: you can keep blocking code and stop paying for the threads. An answer that mentions that trade honestly will beat one that praises reactive programming.

### 12. A service is fine for an hour and then degrades. How do you diagnose it?

Answer with a sequence. Something that worsens over time is accumulating: a connection or thread leak, an unbounded cache, a growing retry queue. Check whether latency rises before or after memory, because the order tells you which is the cause. Take a thread dump while it is bad and look for threads blocked on the same monitor or waiting on the connection pool. Compare heap before and after a forced collection to distinguish a leak from a working set that is simply large.

The failure mode in candidates is naming a tool. The thing being tested is whether you reason from the shape of the symptom to a class of cause.

### 13. How do you test a Spring Boot application without making the suite slow?

By being deliberate about which tests need a context at all. Most business logic can be tested with plain JUnit and constructors, which is why constructor injection matters. Slice tests like `@WebMvcTest` and `@DataJpaTest` load part of the context. Full `@SpringBootTest` is for the few paths that genuinely need the whole application.

The detail that shows experience: Spring caches contexts between test classes, keyed by configuration. Every variation in properties, mocked beans or active profiles creates another context to build and hold in memory. A suite that is slow and memory-hungry usually has dozens of slightly different contexts, and consolidating them is often the single biggest win available.

## How to prepare

Start one application with `--debug` and read the condition evaluation report to the end. It is long and it is the single most useful hour you can spend, because after it auto-configuration stops being magic and becomes a list of decisions you can inspect.

Then take something you built and deliberately break it: remove a bean and read the failure, call a `@Transactional` method from inside its own class and watch the rollback not happen. Interviewers ask about failures, and the people who answer best are the ones who have caused them on purpose.

## Sources

- [Spring Framework reference, declarative transaction management](https://docs.spring.io/spring-framework/reference/data-access/transaction/declarative/annotations.html) - proxy semantics and self-invocation
- [Spring Boot reference, externalized configuration](https://docs.spring.io/spring-boot/reference/features/external-config.html) - the precedence order
- [HikariCP, About Pool Sizing](https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-Sizing) - why small pools outperform large ones
- [Spring Boot project page](https://spring.io/projects/spring-boot) - current release line

---

Public pages are mirrored here in full. Premium pages are listed with their summary only — the gated body stays behind server-side entitlement checks.
