Backend & APIs

Spring Boot interview questions

Interviewers often probe a candidate's understanding of Spring Boot's core principles like auto-configuration, dependency injection, and how it simplifies building production-ready microservices and web applications. They look for practical experience in developing REST APIs, managing data persistence, and deploying applications, alongside knowledge of its ecosystem and best practices.

16 questions (5 easy · 6 medium · 5 hard), each with what a strong answer covers and where people lose the point. Free to read, no account.

On this page (16 questions)

1.What is Spring Boot auto-configuration and how does it work?

Warm-up

What a strong answer covers

  • Define auto-configuration as Spring Boot's mechanism to automatically configure the application based on classpath dependencies and defined beans.
  • Explain that it reduces boilerplate code and promotes 'convention over configuration'.
  • Provide examples, such as configuring an embedded Tomcat server when `spring-boot-starter-web` is present.
  • Mention `@EnableAutoConfiguration` (part of `@SpringBootApplication`) as the enabler.

Where people lose the point

  • Confusing auto-configuration with component scanning; they are distinct concepts.
  • Failing to explain *how* it works (e.g., through conditional annotations like `@ConditionalOnClass`).
  • Not providing concrete examples of what gets auto-configured.
Link to this question

2.Explain the benefits of Dependency Injection in Spring Boot.

Warm-up

What a strong answer covers

  • Define Dependency Injection (DI) as a design pattern where objects receive their dependencies rather than creating them.
  • List benefits such as loose coupling, improved testability (easy mocking), and enhanced maintainability.
  • Explain how it promotes modularity and reusability of components.
  • Mention how Spring's IoC container manages the lifecycle and injection of these dependencies.

Where people lose the point

  • Simply stating 'it's good' without explaining *why* or providing concrete benefits.
  • Confusing DI with the Inversion of Control (IoC) container itself.
  • Not mentioning how it aids in unit testing.
Link to this question

3.What are the core annotations used to create a RESTful controller in Spring Boot?

Warm-up

What a strong answer covers

  • Identify `@RestController` as the primary annotation, explaining it combines `@Controller` and `@ResponseBody`.
  • List HTTP method mapping annotations: `@GetMapping`, `@PostMapping`, `@PutMapping`, `@DeleteMapping`, `@PatchMapping`.
  • Explain `@RequestMapping` for broader path mapping at class or method level.
  • Mention `@PathVariable` for URI template variables and `@RequestBody` for deserializing request bodies.

Where people lose the point

  • Forgetting `@RestController` or not explaining its composite nature.
  • Listing only one or two HTTP method annotations.
  • Confusing `@RequestParam` with `@PathVariable`.
Link to this question

4.How do you configure properties in a Spring Boot application?

Warm-up

What a strong answer covers

  • Explain that `application.properties` or `application.yml` are the primary files for configuration.
  • Describe how to define properties within these files (key-value pairs).
  • Mention `@Value` annotation for injecting individual properties into beans.
  • Discuss `@ConfigurationProperties` for binding related properties to a Java object.
  • Briefly touch upon externalized configuration sources like environment variables and command-line arguments.

Where people lose the point

  • Only mentioning `application.properties` and not `application.yml`.
  • Not explaining how to *use* the properties within the code (e.g., `@Value`).
  • Ignoring the hierarchy of property sources.
Link to this question

5.What are Spring Boot Starters and why are they useful?

Warm-up

What a strong answer covers

  • Define Spring Boot Starters as a set of convenient dependency descriptors that you can include in your application.
  • Explain that they bundle common dependencies required for a particular feature (e.g., web, data JPA, test).
  • Highlight their usefulness in simplifying build configuration and ensuring compatible versions of libraries.
  • Provide examples like `spring-boot-starter-web` or `spring-boot-starter-data-jpa`.

Where people lose the point

  • Confusing starters with individual libraries or just 'dependencies'.
  • Not explaining the 'convenience' aspect or how they manage transitive dependencies.
  • Failing to mention version compatibility benefits.
Link to this question

6.Explain the `@ComponentScan` annotation and its role in a Spring Boot application.

Core

What a strong answer covers

  • Describe `@ComponentScan` as the mechanism by which Spring discovers components (beans) in your application.
  • Explain that it scans specified packages for classes annotated with `@Component`, `@Service`, `@Repository`, `@Controller`, etc.
  • Mention that `@SpringBootApplication` implicitly includes `@ComponentScan` and defaults to scanning the package of the main application class and its sub-packages.
  • Discuss how to customize the scan base packages if needed.

Where people lose the point

  • Confusing component scanning with auto-configuration.
  • Not explaining *what* it scans for (i.e., specific annotations).
  • Failing to mention the default behavior when used with `@SpringBootApplication`.
Link to this question

7.Describe the lifecycle of a Spring Bean.

Core

What a strong answer covers

  • Outline the key stages: instantiation, population of properties (dependency injection), initialization, and destruction.
  • Explain the role of `BeanPostProcessor` interfaces for custom logic before/after initialization.
  • Mention `InitializingBean` (afterPropertiesSet) and `@PostConstruct` for initialization callbacks.
  • Discuss `DisposableBean` (destroy) and `@PreDestroy` for destruction callbacks.
  • Explain how the IoC container manages these stages.

Where people lose the point

  • Omitting key lifecycle stages or mixing up the order.
  • Not mentioning the role of `BeanPostProcessor` or `BeanFactoryPostProcessor`.
  • Forgetting about destruction callbacks or how they are triggered.
Link to this question

8.Differentiate between `@RestController` and `@Controller` in Spring Boot.

Core

What a strong answer covers

  • Explain that `@Controller` is a general-purpose annotation for Spring MVC controllers, typically used for traditional web applications returning views.
  • Describe `@RestController` as a specialized version of `@Controller` that automatically includes `@ResponseBody`.
  • Clarify that `@ResponseBody` serializes the return value of a method directly into the HTTP response body (e.g., JSON, XML).
  • Conclude that `@RestController` is ideal for building RESTful web services, while `@Controller` is for server-side rendered UIs.

Where people lose the point

  • Stating they are interchangeable or not understanding the role of `@ResponseBody`.
  • Failing to mention the primary use case for each (REST vs. MVC views).
  • Not explaining that `@RestController` is a convenience annotation.
Link to this question

9.How does Spring Data JPA simplify data access compared to traditional JPA?

Core

What a strong answer covers

  • Explain that traditional JPA requires writing boilerplate code for common CRUD operations and query implementations.
  • Describe how Spring Data JPA provides interfaces like `JpaRepository` that automatically generate implementations for basic CRUD methods.
  • Highlight the ability to define custom queries by simply declaring method names following specific conventions (e.g., `findByLastName`).
  • Mention the `@Query` annotation for more complex custom JPQL or native SQL queries, still without needing to write implementation code.
  • Emphasize the reduction in boilerplate, increased productivity, and improved maintainability.

Where people lose the point

  • Not clearly articulating the 'boilerplate' problem that Spring Data JPA solves.
  • Failing to mention the convention-based query methods.
  • Confusing Spring Data JPA with JPA itself.
Link to this question

10.Explain Spring Profiles and provide a use case.

Core

What a strong answer covers

  • Define Spring Profiles as a mechanism to provide environment-specific configurations for an application.
  • Explain how different beans or configuration properties can be active only when a specific profile is enabled.
  • Provide a use case, such as having different database configurations for `dev`, `test`, and `prod` environments.
  • Mention how to activate profiles (e.g., `spring.profiles.active` property, command-line argument, environment variable) and how to define profile-specific properties (e.g., `application-dev.properties`).

Where people lose the point

  • Not providing a concrete, relatable use case.
  • Confusing profiles with externalized configuration in general.
  • Failing to explain *how* to activate or define profiles.
Link to this question

11.What is Spring Boot Actuator and what problems does it solve?

Core

What a strong answer covers

  • Define Spring Boot Actuator as a sub-project that adds production-ready features to Spring Boot applications.
  • Explain that it provides endpoints to monitor and manage the application, such as health checks, metrics, info, and environment details.
  • Discuss problems it solves: gaining insights into a running application, monitoring performance, troubleshooting issues, and managing application state without custom code.
  • Mention common endpoints like `/health`, `/metrics`, `/info`.

Where people lose the point

  • Simply listing features without explaining the 'problems solved' aspect.
  • Not mentioning specific types of information Actuator provides (e.g., health, metrics).
  • Confusing Actuator with general logging or monitoring tools.
Link to this question

12.Explain transaction management in Spring Boot, including `@Transactional`.

Hard

What a strong answer covers

  • Define transaction management as ensuring data integrity and consistency in database operations.
  • Explain that Spring provides declarative transaction management, primarily through the `@Transactional` annotation.
  • Describe how `@Transactional` can be applied to methods or classes, making the method's execution atomic (all or nothing).
  • Discuss key attributes like `propagation` (how transactions interact), `isolation` (level of data visibility), and `rollbackFor` (exceptions that trigger rollback).
  • Mention how Spring Boot auto-configures a transaction manager (e.g., `JpaTransactionManager`) based on dependencies.

Where people lose the point

  • Not explaining the ACID properties or the core purpose of transactions.
  • Failing to mention important `@Transactional` attributes like `propagation` or `rollbackFor`.
  • Confusing declarative transaction management with programmatic transaction management.
Link to this question

13.Describe how you would implement basic authentication and authorization in a Spring Boot application.

Hard

What a strong answer covers

  • Explain that Spring Security is the de-facto standard for security in Spring applications, easily integrated with Spring Boot starters.
  • Describe basic authentication using `spring-boot-starter-security`, which provides default in-memory user details and HTTP Basic authentication.
  • Discuss how to customize user details (e.g., from a database) by implementing `UserDetailsService` and configuring a `PasswordEncoder`.
  • Explain authorization using method-level annotations like `@PreAuthorize` or URL-based authorization in a `WebSecurityConfigurerAdapter` (or `SecurityFilterChain` in newer versions).
  • Mention configuring security rules for different endpoints (e.g., `/admin` requires `ROLE_ADMIN`).

Where people lose the point

  • Not mentioning Spring Security as the framework.
  • Failing to differentiate between authentication (who are you?) and authorization (what can you do?).
  • Overlooking the need for a `PasswordEncoder` when customizing user details.
Link to this question

14.Discuss different testing strategies (unit, integration, slice) for a Spring Boot application.

Hard

What a strong answer covers

  • Define Unit Testing: testing individual components in isolation, typically without Spring context, using mock objects (e.g., Mockito).
  • Define Integration Testing: testing the interaction between multiple components, often with a partial or full Spring context, using `@SpringBootTest`.
  • Explain Slice Testing: testing specific layers of the application (e.g., web layer with `@WebMvcTest`, data layer with `@DataJpaTest`) with a minimal Spring context.
  • Discuss the benefits of each strategy (speed, coverage, confidence) and when to use them.
  • Mention common testing annotations and utilities like `TestRestTemplate`, `MockMvc`, and H2 database for in-memory testing.

Where people lose the point

  • Confusing unit and integration tests, or not understanding the scope of each.
  • Not mentioning slice testing or its benefits for faster integration tests.
  • Failing to provide specific Spring Boot testing annotations or tools.
Link to this question

15.Explain the concept of embedded servers in Spring Boot and their advantages.

Hard

What a strong answer covers

  • Define embedded servers (e.g., Tomcat, Jetty, Undertow) as web servers that are packaged directly within the Spring Boot application's JAR file.
  • Explain that this eliminates the need for a separate application server installation and deployment (e.g., WAR files to external Tomcat).
  • List advantages: simplified deployment (just run the JAR), self-contained applications, easier development and testing, and consistent runtime environments.
  • Mention how Spring Boot auto-configures the embedded server based on the `spring-boot-starter-web` dependency.
  • Discuss how to switch between different embedded servers or configure them.

Where people lose the point

  • Not clearly explaining *what* an embedded server is or how it differs from traditional deployment.
  • Failing to list the key advantages, especially simplified deployment.
  • Not mentioning the common embedded server options.
Link to this question

16.How would you create a custom Spring Boot Starter?

Hard

What a strong answer covers

  • Explain the purpose of a custom starter: to provide a reusable, opinionated set of dependencies and auto-configurations for a specific library or feature.
  • Outline the two main components: the 'starter' module (e.g., `my-library-spring-boot-starter`) and the 'auto-configure' module (e.g., `my-library-spring-boot-autoconfigure`).
  • Describe the auto-configure module's role in defining `@Configuration` classes with conditional logic (`@ConditionalOnClass`, `@ConditionalOnMissingBean`) to provide default beans.
  • Explain the `spring.factories` file in `META-INF` to register the auto-configuration classes.
  • Detail the starter module's role in simply providing the necessary transitive dependencies, including the auto-configure module.

Where people lose the point

  • Confusing the starter module with the auto-configure module.
  • Forgetting the `spring.factories` file or its purpose.
  • Not explaining the role of conditional annotations in the auto-configure module.
Link to this question
No account needed

Answer one real Spring Boot question now

A question a Spring Boot panel actually asks, answered out loud, scored on what you said and how you said it. Under two minutes, and nothing to sign up for.

What is Spring Boot auto-configuration and how does it work?

We never store the audio. Your answer is deleted within 24 hours unless you save the result.

How Spring Boot answers get judged

The weights a Spring Boot interviewer is holding, whether or not they say so out loud. Round Zero scores your practice answers against exactly these, and quotes your own words back as the evidence for each.

Technical Correctness

30%

The accuracy and precision of the technical details provided, ensuring no factual errors or misunderstandings of Spring Boot concepts.

Conceptual Depth and Understanding

30%

The extent to which the candidate demonstrates a deep understanding of underlying principles, not just surface-level knowledge or memorization.

Practical Application and Best Practices

25%

Ability to discuss how concepts are applied in real-world scenarios, including awareness of common patterns, anti-patterns, and best practices.

Clarity and Structure of Explanation

15%

The ability to articulate complex ideas clearly, concisely, and in a well-structured manner, making them easy to follow.

Related Backend & APIs skills

All skills →

Now say them out loud

You have read what strong Spring Boot answers contain. The next thing that moves the needle is producing one under time, out loud, and finding out where it falls apart.

  • These questions asked back, with follow-ups
  • Flashcards for the ones you keep missing
  • A scored mock that quotes your own answers

Browse every skill

Practising Spring Boot: common questions

What Spring Boot interview questions should I practice?
Start with the core areas Spring Boot interviewers probe: What is Spring Boot auto-configuration and how does it work; Explain the benefits of Dependency Injection in Spring Boot.; What are the core annotations used to create a RESTful controller in Spring Boot. This page outlines strong answers and common mistakes, and the scored path drills each one with follow-ups.
Is the Spring Boot practice free?
Yes. The Spring Boot path runs free inside Round Zero: lessons, practice questions and flashcards. Drills are unlimited on every plan, free included. So is the full scorecard. Free also covers 3 complete scored interviews, no card.
How is this different from a Spring Boot question list?
A static list gives you questions with no feedback. Round Zero runs a live scored practice that probes your actual answers, rotates difficulty, and tells you exactly what to fix, grounded in a Spring Boot rubric.
How should I prepare for a Spring Boot interview?
Learn the concepts, drill the questions until answers come fast, then prove it in a scored mock. Round Zero sequences all three so you know you are ready, not just that you read about Spring Boot.
How is a Spring Boot answer scored?
Spring Boot answers are scored on technical correctness, conceptual depth and understanding, practical application and best practices, clarity and structure of explanation, with evidence quoted from what you actually said, so feedback is specific instead of generic praise.