Key Takeaways
- Spring Boot interviews blend core Java knowledge with framework-specific questions about dependency injection and configuration.
- You should be able to explain what the IoC container actually does, not just that '@Autowired injects dependencies'.
- REST API questions test both syntax and judgment — status codes, validation, and exception handling structure matter as much as endpoint mapping.
- Spring Data JPA questions often probe whether you understand what's happening underneath a repository method, not just that it 'just works'.
- Testing questions distinguish candidates who write unit tests from those who only know how to run the application manually.
Spring Boot interviews sit at the intersection of core Java fundamentals and framework-specific conventions. Because Spring Boot automates so much configuration that used to be explicit in older Spring applications, it's possible to build working applications without fully understanding what the framework is doing behind the scenes — which is exactly what interviewers probe for. This guide covers the questions that come up most often, from dependency injection fundamentals through to REST API design and testing.
Why Spring Boot Interviews Blend Framework and Java Fundamentals
A candidate who's only used Spring Boot's auto-configuration and annotations without understanding the underlying Inversion of Control container can usually get an application running, but struggles when asked to explain why something works, or to debug a configuration issue that auto-configuration doesn't handle cleanly. Interviewers use this gap deliberately to distinguish surface familiarity from real understanding.
Core Concepts
"What is Inversion of Control, and how does dependency injection relate to it?" IoC means the
framework, not your code, controls the creation and wiring of objects — your classes declare what
they need, and the container supplies it. Dependency injection is the specific mechanism Spring uses
to implement IoC: instead of a class instantiating its own dependencies with new, they're provided
(injected) from outside, typically via constructor injection.
@Service
public class OrderService {
private final PaymentClient paymentClient;
// Constructor injection — preferred over field injection for testability
public OrderService(PaymentClient paymentClient) {
this.paymentClient = paymentClient;
}
}
"Why is constructor injection generally preferred over field injection?" Constructor injection
makes dependencies explicit and required at construction time, which makes the class easier to test
(you can pass mocks directly without reflection) and prevents the object from existing in a
partially-initialized state. Field injection (@Autowired directly on a field) works, but hides the
dependency graph and makes unit testing without a Spring context noticeably more awkward.
"What's the difference between @Component, @Service, and @Repository?" All three register
a class as a Spring-managed bean, and functionally @Component would work in any of these places.
The distinction is semantic: @Service signals business logic, @Repository signals data access
(and enables persistence-specific exception translation), and using the specific annotation
communicates intent to other developers reading the code, even though the container treats them
almost identically under the hood.
Building REST APIs
"Walk me through building a REST endpoint that returns a 404 when a resource isn't found."
@RestController
@RequestMapping("/api/orders")
public class OrderController {
private final OrderService orderService;
public OrderController(OrderService orderService) {
this.orderService = orderService;
}
@GetMapping("/{id}")
public ResponseEntity<Order> getOrder(@PathVariable Long id) {
return orderService.findById(id)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
}
Interviewers are watching for whether you handle the "not found" case explicitly rather than letting
a null propagate, and whether you know the correct status code conventions (200 for success, 201
for creation, 400 for bad input, 404 for missing resources, 409 for conflicts).
"How do you handle validation and centralized error handling?" Bean validation annotations
(@Valid, @NotNull, @Size) on request DTOs combined with a @ControllerAdvice class handling
exceptions globally is the standard pattern — it keeps individual controllers free of repetitive
try/catch blocks and produces consistent error responses across the API.
Mentioning that you'd return a structured error body (not just a bare status code) — with a message, timestamp, and error code — for client-facing APIs signals production experience beyond "the endpoint returns the right status."
Data Layer Questions
"What does Spring Data JPA actually do when you define a repository interface with no implementation?"
public interface OrderRepository extends JpaRepository<Order, Long> {
List<Order> findByCustomerId(Long customerId);
}
Spring generates a proxy implementation at runtime, parsing the method name (findByCustomerId)
into the corresponding query automatically — this is query derivation, and it's worth being able to
explain that it works by convention over the method's naming pattern, not magic.
"What's the difference between @Transactional at the service layer versus the repository
layer?" @Transactional is typically applied at the service layer, wrapping a full business
operation (which might touch multiple repositories) in a single transaction boundary — placing it at
the repository layer would fragment what should logically be one atomic operation into several
separate transactions.
Configuration and Profiles
Expect a question about environment-specific configuration — application.yml (or .properties)
with Spring profiles (application-dev.yml, application-prod.yml) activated via
spring.profiles.active. This is a practical, frequently-tested area because misconfigured
environments are a common real-world source of production incidents.
Spring Boot's auto-configuration is designed to be invisible when it works — which is exactly why interviewers ask you to explain what's happening underneath it.
Testing Questions
@SpringBootTestloads the full application context — useful for integration tests, but slower and heavier than needed for most unit tests.@WebMvcTestloads only the web layer, ideal for testing controllers in isolation with mocked service dependencies.- Mocking dependencies with Mockito (
@MockBean) to isolate the class under test from its collaborators, rather than testing against a real database or external service in every test.
A candidate who can explain when to reach for a narrower test slice instead of always loading the full application context signals real testing discipline, not just "I know how to write a test."
Common Practical Questions
- Spring Security basics: how authentication and authorization are configured, and the difference between the two.
- Actuator: built-in endpoints for health checks and metrics, commonly used for monitoring in production.
- Microservices considerations: if the role touches distributed systems, expect a question about how services communicate (REST, messaging) and how configuration and service discovery are handled across services.
Mistakes to Avoid
- Defaulting to field injection out of habit rather than explaining why constructor injection is generally preferred
- Not knowing what
@Transactionalactually guarantees (atomicity within the boundary) versus what it doesn't (it won't protect against issues outside the transaction, like external API calls) - Treating all three stereotype annotations (
@Component/@Service/@Repository) as functionally distinct when the real distinction is semantic, not mechanical - Being unable to explain query derivation in Spring Data JPA beyond "you just name the method correctly"
How to Prepare
Review a Spring Boot project you've built or contributed to and be ready to explain, out loud, why specific architectural choices were made — why a class was structured a certain way, why a particular exception-handling pattern was used, what a specific configuration property actually controls. Interviewers respond better to reasoned trade-offs from real code than to definitions recited from documentation.
Put this into practice.
Start a free AI-powered mock interview — real follow-up questions, instant feedback, no card required.