All interview guides

Spring Boot Interview Questions and Answers

24 questions that come up in Spring Boot technical interviews, each with the answer and an explanation of why it is right.

Test yourself — 90 question bank

1. What is Spring Cloud?

Advanced

Answer: Framework for building microservices and cloud-native apps

Spring Cloud provides tools for building microservices: service discovery, config management, circuit breakers, API gateway, distributed tracing.

2. What is Spring Data JPA?

Intermediate

Answer: Simplifies data access using JPA with repository abstraction

Spring Data JPA simplifies data access layer by providing repository interfaces with automatic implementation. Built on top of JPA (Hibernate).

3. What is Spring Boot?

Beginner

Answer: Framework that simplifies Spring application development

Spring Boot is an opinionated framework built on top of Spring Framework that simplifies configuration and deployment with auto-configuration and embedded servers.

4. What is JpaRepository?

Intermediate

Answer: Repository interface providing CRUD operations

JpaRepository extends PagingAndSortingRepository, providing CRUD operations, pagination, and batch operations out of the box.

5. What is Eureka?

Advanced

Answer: Service discovery server for microservices

Eureka is service discovery server. Microservices register themselves, discover other services. Part of Netflix OSS, integrated with Spring Cloud.

6. What is the main advantage of Spring Boot?

Beginner

Answer: Auto-configuration and convention over configuration

Spring Boot provides auto-configuration, starter dependencies, embedded servers, and production-ready features, reducing boilerplate configuration significantly.

7. What is Spring Cloud Config?

Advanced

Answer: Centralized configuration management for distributed systems

Spring Cloud Config provides centralized configuration management. Config server stores configurations, clients fetch them. Supports Git, SVN, file system.

8. What annotation marks the main class?

Beginner

Answer: @SpringBootApplication

@SpringBootApplication combines @Configuration, @EnableAutoConfiguration, and @ComponentScan. Marks the main entry point class.

9. What is API Gateway pattern?

Advanced

Answer: Single entry point for microservices routing requests

API Gateway is single entry point for microservices. Handles routing, authentication, rate limiting, load balancing. Spring Cloud Gateway or Zuul.

10. How do you run a Spring Boot application?

Beginner

Answer: Run main method with SpringApplication.run()

Run the main method containing SpringApplication.run(Application.class, args). Can also use Maven/Gradle plugins or java -jar.

11. What is Circuit Breaker pattern?

Advanced

Answer: Prevents cascading failures in distributed systems

Circuit Breaker prevents cascading failures. Stops calling failing service, provides fallback. Use Resilience4j or Netflix Hystrix (deprecated).

12. What is dependency injection?

Beginner

Answer: Design pattern where objects receive dependencies from external source

Dependency injection is a design pattern where objects receive their dependencies from an external source (Spring container) rather than creating them.

13. What is @GeneratedValue?

Intermediate

Answer: Specifies primary key generation strategy

@GeneratedValue specifies primary key generation strategy. Strategies: AUTO, IDENTITY, SEQUENCE, TABLE. Usually AUTO for database-specific strategy.

14. What is Resilience4j?

Advanced

Answer: Fault tolerance library with circuit breaker, rate limiter

Resilience4j is lightweight fault tolerance library. Provides circuit breaker, rate limiter, retry, bulkhead, time limiter. Modern alternative to Hystrix.

15. What is IoC (Inversion of Control)?

Beginner

Answer: Framework controls object lifecycle instead of application

IoC is a principle where the framework (Spring) controls the creation and lifecycle of objects, inverting the traditional control flow.

16. What are query methods?

Intermediate

Answer: Repository methods derived from method names

Query methods are repository interface methods where Spring Data generates queries from method names. Example: findByName, findByAgeGreaterThan.

17. What is distributed tracing?

Advanced

Answer: Traces requests across microservices

Distributed tracing traces requests across microservices. Shows complete request flow, latency. Use Spring Cloud Sleuth with Zipkin or Jaeger.

18. What is the Spring Container?

Beginner

Answer: IoC container managing beans and their lifecycle

Spring Container (ApplicationContext) is the IoC container that instantiates, configures, and manages beans and their dependencies.

19. What is Spring Security?

Intermediate

Answer: Authentication and authorization framework

Spring Security provides comprehensive authentication and authorization framework. Handles login, password encoding, role-based access, OAuth2, JWT.

20. What is Spring Cloud Sleuth?

Advanced

Answer: Adds trace and span IDs to logs for distributed tracing

Spring Cloud Sleuth adds distributed tracing capabilities. Adds trace ID and span ID to logs. Integrates with Zipkin for visualization.

21. What is a Bean?

Beginner

Answer: Object managed by Spring container

A Bean is an object that is instantiated, assembled, and managed by the Spring IoC container. Defined via @Component, @Bean, or XML.

22. What is caching in Spring Boot?

Advanced

Answer: Stores frequently accessed data to improve performance

Caching stores frequently accessed data in memory to improve performance. Spring supports multiple cache providers: EhCache, Caffeine, Redis, Hazelcast.

23. What is @PreAuthorize?

Intermediate

Answer: Method-level security checking authorization before execution

@PreAuthorize checks authorization before method execution. Use SpEL expressions: @PreAuthorize("hasRole('ADMIN')"). Requires @EnableGlobalMethodSecurity.

24. What does @Component do?

Beginner

Answer: Marks class as Spring-managed component

@Component marks a class as a Spring-managed component. Spring auto-detects and registers it as a bean during component scanning.

Ready to test yourself?

The full Spring Boot bank has 90 questions across 3 difficulty levels — timed, shuffled, and scored.

Take the Spring Boot quiz