,

Top 20 Spring Boot Interview Questions and Answers for Java Developers

By the HiReXL Career Team

Spring Boot is the default framework for building Java microservices and enterprise REST APIs, which makes Spring Boot interview questions a core part of Java developer, Java full stack and backend engineer interviews. This guide covers the top 20 Spring Boot interview questions and answers, from auto-configuration and dependency injection to JPA, transactions, security, microservices and testing.

Use it with our Java interview guide to cover both the language and the framework.

Spring Boot fundamentals

1. What is Spring Boot and how is it different from the Spring Framework?

Spring Framework provides dependency injection, MVC, data access and more, but needs a lot of configuration. Spring Boot adds auto-configuration, starter dependencies, an embedded server (Tomcat, Jetty or Undertow), externalized configuration and production features, so you can build a runnable application with minimal setup.

2. What does @SpringBootApplication do?

It combines @Configuration, @EnableAutoConfiguration and @ComponentScan. It marks the main class, enables auto-configuration and scans the package and sub-packages for components.

3. How does auto-configuration work?

Spring Boot loads auto-configuration classes listed in the auto-configuration imports file and applies them conditionally with annotations like @ConditionalOnClass, @ConditionalOnMissingBean and @ConditionalOnProperty. Your own beans take priority. Use the --debug flag or the conditions endpoint to see what was applied.

4. What are Spring Boot starters?

Starters are dependency descriptors such as spring-boot-starter-web, -data-jpa, -security and -test that pull in a consistent, tested set of libraries for a capability.

5. How do profiles and externalized configuration work?

Configuration comes from application.properties or YAML, environment variables, command-line arguments and config servers, in a defined order of precedence. Profiles such as dev, test and prod activate profile-specific files and beans with spring.profiles.active. Bind settings to typed classes with @ConfigurationProperties.

Dependency injection and beans

6. What is dependency injection and which type is preferred?

DI means the container supplies an object’s dependencies instead of the object creating them. Constructor injection is preferred because dependencies are explicit, can be final and the class is easy to test. Field injection with @Autowired is discouraged.

7. What are bean scopes?

Singleton (default, one per container), prototype (new instance per request for the bean), and web scopes: request, session and application. Be careful injecting a prototype or request-scoped bean into a singleton.

8. What is the difference between @Component, @Service, @Repository and @Controller?

All register beans via component scanning. @Service and @Controller express intent; @Repository also translates persistence exceptions; @RestController combines @Controller and @ResponseBody.

REST APIs and data access

9. How do you build and handle errors in a REST API with Spring Boot?

Use @RestController with @GetMapping, @PostMapping and similar, validate input with @Valid and Jakarta Bean Validation, and handle errors centrally with @RestControllerAdvice and @ExceptionHandler, returning consistent responses such as RFC 9457 ProblemDetail.

10. What is Spring Data JPA?

It provides repository interfaces like JpaRepository that generate CRUD operations and queries from method names, plus @Query for custom JPQL or native SQL, paging and sorting, and projections. Hibernate is the default JPA provider.

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

Loading a list of entities and then lazily loading a relation for each one triggers one extra query per row. Fix it with fetch joins, @EntityGraph, batch fetching or DTO projections, and detect it by logging SQL.

12. How does @Transactional work?

It wraps the method in a proxy that starts, commits or rolls back a transaction. By default it rolls back on unchecked exceptions only. It does not apply to private methods or self-invocation within the same class. Propagation (REQUIRED, REQUIRES_NEW) and isolation levels control behavior.

Security, microservices and operations

13. How do you secure a Spring Boot application?

Use Spring Security with a SecurityFilterChain bean, authenticate with OAuth 2.0/OpenID Connect or JWT resource server support, use method security with @PreAuthorize, hash passwords with BCrypt, configure CORS and CSRF correctly and keep dependencies patched.

14. What is Spring Boot Actuator?

Actuator adds production endpoints such as health, info, metrics, env and loggers. Combine it with Micrometer to export metrics to Prometheus, Datadog or CloudWatch, and expose only the endpoints you need behind security.

15. How do you build microservices with Spring Boot and Spring Cloud?

Common pieces are Spring Cloud Gateway, config server, service discovery (or Kubernetes services), OpenFeign or WebClient for calls, Resilience4j for circuit breakers and retries, Spring Cloud Stream or Kafka for events, and distributed tracing with Micrometer Tracing and OpenTelemetry.

16. What is the difference between RestTemplate, WebClient and RestClient?

RestTemplate is the older blocking client in maintenance mode. WebClient is reactive and non-blocking. RestClient is the modern synchronous client with a fluent API. Declarative HTTP interfaces can also be used.

17. How do you test Spring Boot applications?

Unit test with JUnit 5 and Mockito, use slice tests such as @WebMvcTest and @DataJpaTest, full integration tests with @SpringBootTest, and Testcontainers for real databases and Kafka in tests.

Scenario questions

18. Scenario: an API is slow under load. How do you investigate?

Check Actuator metrics, APM traces and database logs. Look for N+1 queries, missing indexes, small connection pool (HikariCP) settings, blocking calls to slow services without timeouts, and large payloads. Add caching, pagination, timeouts with circuit breakers and consider virtual threads in Java 21+.

19. What is the difference between @Controller and @RestController?

@Controller returns view names for server-rendered pages with Thymeleaf or JSP. @RestController adds @ResponseBody so return values are serialized to JSON or XML, which is what REST APIs need.

20. What are Spring Boot DevTools and what happens at startup?

DevTools provides automatic restart and live reload in development. At startup Spring Boot creates the application context, applies auto-configuration, scans components, binds properties, starts the embedded server and runs CommandLineRunner or ApplicationRunner beans.

How to prepare for a Spring Boot interview

  • Build a REST microservice with validation, JPA, Spring Security (JWT), Actuator, Docker and tests with Testcontainers.
  • Be ready to explain what happens at startup and how a request flows through filters, DispatcherServlet and controllers.
  • Know Java 17/21 features such as records, sealed classes and virtual threads.
  • Understand microservice patterns: API gateway, circuit breaker, saga and event-driven design.

Pair this with our Java interview questions, system design interview and Docker interview questions.

Frequently asked questions

What Spring Boot topics are asked most?

Auto-configuration, starters, dependency injection, REST controllers, exception handling, Spring Data JPA, @Transactional, Spring Security, Actuator, profiles and testing.

What Spring Boot questions are asked for experienced developers?

Microservice design, Spring Cloud, performance tuning, transaction propagation, security with OAuth 2.0, observability and migrations to Spring Boot 3 and Jakarta EE.

Do I need Spring Boot 3 knowledge?

Yes. Spring Boot 3 requires Java 17+, moved to Jakarta EE namespaces and added native image and observability improvements, and most new projects use it.

Got the interview? Make sure your resume tells the same story.

Interviewers read your resume right before they talk to you. HiReXL aligns it with the job description’s keywords so your experience and your answers match. HiReXL is built by 4As Consulting, a cloud and DevOps consulting firm. Looking for your next role? Submit your resume for open positions with PanAmerica Inc.

See how HiReXL helps →