50 Advanced Spring Boot Interview Questions & Answers (2025)
Are you preparing for a Spring Boot interview? Below are 50 of the most complex and frequently asked Spring Boot questions—complete with clear, concise answers for each. These cover the latest practices and insights for 2025, from architecture and production-readiness to troubleshooting and microservices!
1. What is Spring Boot and how is it different from the Spring Framework?
Spring Boot is an extension of the Spring Framework focusing on convention over configuration, autoconfiguration, and embedded server support. Unlike classic Spring, Spring Boot reduces boilerplate and external configuration, enabling fast stand-alone application development.
2. Explain the concept of auto-configuration in Spring Boot.
Auto-configuration automatically configures application components based on available classes and dependencies on the classpath, minimizing manual setup using the @EnableAutoConfiguration
annotation.
3. How does Spring Boot manage application properties?
Spring Boot uses application.properties
or application.yml
for configuration, allowing hierarchical overrides and bean injection via @Value
or @ConfigurationProperties
.
4. What is the purpose of the @SpringBootApplication annotation?
@SpringBootApplication
is a meta-annotation combining @SpringBootConfiguration
, @EnableAutoConfiguration
, and @ComponentScan
, enabling core Spring Boot features.
5. Describe how Spring Boot starters simplify dependency management.
Starters, like spring-boot-starter-web
, are curated dependency sets that eliminate manual dependency resolution and version conflicts.
6. Explain the difference between @Component, @Service, and @Repository in Spring Boot.
@Component
: Generic stereotype for any bean.@Service
: Indicates service-layer beans.@Repository
: Indicates the data-access layer and enables exception translation.
7. How do you handle external configuration in Spring Boot?
Properties can be handled via properties/yaml files, environment variables, command-line args, and custom config files using @PropertySource
.
8. What is the Spring Boot Actuator and why is it important?
Spring Boot Actuator provides endpoints for monitoring and managing applications (health, metrics, environment, etc.), making production management and DevOps integration easier.
9. How do you enable CORS in Spring Boot?
Enable CORS globally using WebMvcConfigurer
and overriding addCorsMappings
, or use @CrossOrigin
at the controller/method level for granular control.
10. What are profiles in Spring Boot and how are they used?
Profiles let you define environment-specific bean configurations. Use @Profile("dev")
to activate a bean only in the dev profile, and set active profiles via spring.profiles.active
.
11. How is security implemented in Spring Boot?
Security is implemented via Spring Security starter. Configure authentication providers, user details, CSRF, and role-based authorization through Java config or properties.
12. Difference between @RestController and @Controller annotations?
@RestController
combines @Controller
and @ResponseBody
, returning JSON/XML by default, while @Controller
returns views/templates.
13. Describe the use of the @Transactional annotation.
@Transactional
manages transactionality, specifying rollback, propagation, and isolation. Applied to service/repository layers for data consistency.
14. Explain embedded servers in Spring Boot.
Spring Boot applications include embedded servers (Tomcat, Jetty, Undertow) inside the executable JAR – no need to deploy WARs or use an external server.
15. How do you customize error handling in Spring Boot?
Via custom error pages, implementing ErrorController
, or using @ControllerAdvice
and @ExceptionHandler
for centralized exception handling.
16. How is caching configured and used in Spring Boot?
Enable caching using @EnableCaching
and manage cache with @Cacheable
, @CachePut
, @CacheEvict
annotations and configure cache manager (Ehcache, Redis, etc.).
17. What is the role of CommandLineRunner and ApplicationRunner?
These interfaces run code after application startup (initialization, setup). Implement by overriding their run
methods in beans.
18. Explain how Spring Boot supports internationalization (i18n).
Define messages in locale-specific properties (messages_en.properties
, etc.), and use MessageSource
for fetching localized messages.
19. What is DevTools in Spring Boot?
DevTools provides live reload, auto-restart on code changes, and advanced debugging support, thus improving developer experience during application development.
20. How are file uploads handled in Spring Boot?
Define endpoints with @RequestParam("file") MultipartFile file
. Optionally configure MultipartResolver
. Always validate input for security.
21. Describe the hierarchy of property sources in Spring Boot.
Order is: defaults → application.properties
/application.yml
→ profile-specific → env vars/command line → system properties. Later sources override earlier ones.
22. How do you implement custom logging in Spring Boot?
Customize default Logback via application.properties
, logback.xml
, or use @Slf4j
(Lombok) for logging in classes.
23. What are Spring Boot Starter Projects?
Starters aggregate dependencies (e.g., spring-boot-starter-web
, spring-boot-starter-data-jpa
) for common tasks, reducing manual management and setup.
24. How does Spring Boot support service discovery?
Via Spring Cloud integration (Netflix Eureka, Consul), which registers and enables microservices to find each other.
25. What is Spring Initializr?
A web tool to generate Spring Boot projects with selected starters, metadata, and structure for rapid setup.
26. How do you define custom actuators in Spring Boot?
Implement and annotate classes with @Endpoint
or @ReadEndpoint
to expose custom info on /actuator/{custom}
.
27. How do you handle REST versioning in Spring Boot?
Use URL versioning (/api/v1/resource
), request params, headers, or content negotiation for versioning REST APIs.
28. What are the different ways to run a Spring Boot application?
Run via java -jar
, mvn spring-boot:run
, from an IDE, or as a Docker container.
29. What mechanisms are available for scheduling tasks in Spring Boot?
Enable with @EnableScheduling
, and annotate scheduled methods with @Scheduled
(cron, fixed-rate, fixed-delay).
30. Describe best practices for exception handling in Spring Boot REST APIs.
Use @ControllerAdvice
for global handlers, meaningful error messages, and extend ResponseEntityExceptionHandler
for customizations.
31. How do you secure REST APIs using JWT in Spring Boot?
Combine spring-security
, a JWT library, custom filters to extract/validate tokens, and configure authentication providers for stateless security.
32. What is a health indicator in Spring Boot Actuator?
A component exposing health status for services (database, queue). Customize by implementing the HealthIndicator
interface.
33. How can you optimize Spring Boot applications for performance?
Use caching, minify static files, tune threadpools, DB indexing, profile memory/CPU, and use metrics from Actuator.
34. How do you enable HTTPS in a Spring Boot application?
Add server.ssl.*
properties, generate a certificate (keystore), and configure path/password in application.properties
.
35. What is Circuit Breaker and how do you implement it in Spring Boot?
A pattern to prevent cascading failures in microservices; implement with Resilience4j or Hystrix libraries for fallback logic and resilience.
36. How does Spring Boot enable API Gateway functionalities?
By integrating with Spring Cloud Gateway or Zuul, providing routing, filtering, rate limiting, and load balancing for your APIs/microservices.
37. Explain event-driven communication in Spring Boot.
Use @EventListener
with ApplicationEvent
or integrate with brokers (Kafka, RabbitMQ) for async, decoupled communication.
38. How does Spring Boot support reactive programming?
Via WebFlux and Project Reactor (Mono
, Flux
), enabling non-blocking, reactive patterns for high scalability.
39. How do you integrate Spring Boot with NoSQL databases?
Add starters (spring-boot-starter-data-mongodb
, etc.), configure connections, and use repository abstractions for CRUD operations.
40. What is HATEOAS and how is it supported in Spring Boot?
Hypermedia as the Engine of Application State: add navigational links to REST responses using spring-hateoas
for better discoverability.
41. How can you run different beans depending on active profiles?
Use @Profile("profile_name")
on beans or configs to instantiate them only under matching profiles.
42. What is the difference between @RequestParam and @PathVariable?
@RequestParam
maps query parameters, while @PathVariable
maps URI segments directly to method arguments.
43. How can you configure custom validation for request bodies in Spring Boot?
Use validation annotations (@Valid
, @NotNull
), and define custom validators with @InitBinder
for advanced logic.
44. What is a Feign client and how do you use it in Spring Boot?
Feign is a declarative HTTP client (spring-cloud-starter-openfeign
), use @FeignClient
interface methods to call REST endpoints directly.
45. How do you implement rate limiting in Spring Boot APIs?
Use libraries like Bucket4j/Redis, or enforce at API Gateway level (Spring Cloud Gateway).
46. What are configuration properties binding and its advantages?
@ConfigurationProperties
binds grouped properties to POJOs, ensuring type-safety and cleaner code organization.
47. How are scheduled tasks monitored and managed in Spring Boot?
Leverage Actuator endpoints or integrate with monitoring solutions (Prometheus, Grafana) for scheduled task stats.
48. How can you customize the embedded servlet container configuration?
Override properties (port, context path), or implement WebServerFactoryCustomizer
for advanced settings.
49. What are the key considerations for deploying a Spring Boot app to a container?
Use a proper Dockerfile, externalize configuration, set up readiness/liveness endpoints, expose appropriate ports, and enable metrics/logging.
50. How do you approach debugging and tracing issues in a distributed Spring Boot system?
Enable distributed tracing (Sleuth, Zipkin, Jaeger), aggregate logs (ELK stack), and monitor Actuator/APM metrics for effective troubleshooting.