Spring Boot Interview Questions & Answers (2025)
Spring Boot is widely used for building enterprise-grade Java applications and microservices. This guide provides detailed explanations, examples, and ready-to-use code snippets for 30 frequently asked interview questions.
1. What is Spring Boot?
Explanation:
Spring Boot is a framework built on top of Spring to simplify Spring application development. It provides auto-configuration, embedded servers, starter dependencies, and a convention-over-configuration approach.
Features:
-
Auto-configuration
-
Embedded Tomcat, Jetty, or Undertow servers
-
Starter dependencies for easy project setup
-
Microservice-ready architecture
Example:
2. Difference between Spring and Spring Boot
| Feature | Spring | Spring Boot |
|---|---|---|
| Setup | Complex, XML-based | Auto-configured, annotation-based |
| Server | Requires external server | Embedded server (Tomcat, Jetty) |
| Deployment | WAR file | JAR file (standalone) |
| Focus | General-purpose framework | Rapid microservice development |
3. What are Spring Boot Starters?
Starters are pre-configured dependency sets to simplify dependency management.
Example:
Adds everything needed for building REST APIs: Spring MVC, Jackson, and embedded Tomcat.
4. Explain Spring Boot Auto-Configuration
Spring Boot automatically configures beans based on the classpath. This reduces manual configuration.
Diagram (text-based):
Example:
5. What is @SpringBootApplication?
@SpringBootApplication is a meta-annotation combining:
-
@Configuration– Marks class as a configuration -
@EnableAutoConfiguration– Enables auto-configuration -
@ComponentScan– Scans components automatically
Example:
6. Difference between @Component, @Service, @Repository, @Controller
| Annotation | Usage |
|---|---|
| @Component | Generic bean definition |
| @Service | Business/service layer |
| @Repository | DAO layer, handles DB exceptions |
| @Controller | Handles HTTP requests |
7. What is Spring Boot Actuator?
Explanation:
Provides production-ready features like monitoring, metrics, and health checks.
Example:
Access health endpoint:
8. How to Externalize Configuration in Spring Boot
Spring Boot supports application.properties or application.yml.
Example:
9. What is @Value Annotation?
Injects values from configuration files.
10. Difference between @RestController and @Controller
| Annotation | Usage |
|---|---|
| @Controller | Returns views (JSP, Thymeleaf) |
| @RestController | Returns JSON/XML directly |
11. How to handle exceptions in Spring Boot
Explanation: Use @ControllerAdvice and @ExceptionHandler to handle global exceptions.
12. What is Spring Boot DevTools?
Provides hot reload and automatic restart for development.
Dependency:
13. What are Profiles in Spring Boot?
Profiles allow environment-specific configurations.
Example:
Activate:
14. Spring Boot Security
Provides authentication and authorization using spring-boot-starter-security.
15. Difference between @EnableAutoConfiguration and @SpringBootApplication
-
@EnableAutoConfiguration: Enables auto-configuration only -
@SpringBootApplication: Combines auto-configuration, component scan, and configuration
16. Embedded Server in Spring Boot
Spring Boot provides embedded servers, so no WAR deployment needed.
Run standalone app:
17. Spring Boot CLI
Run Spring Boot apps from the command line using Groovy scripts:
18. Connect Spring Boot to a Database
Example: MySQL with JPA
19. Difference between @Entity and @Table
| Annotation | Usage |
|---|---|
| @Entity | Marks a class as JPA entity |
| @Table | Maps entity to specific table |
20. Spring Boot JPA Repositories
Automatically implements CRUD operations.
21. Caching in Spring Boot
22. Scheduling in Spring Boot
23. Testing in Spring Boot
24. DevTools vs LiveReload
-
DevTools: Auto-restarts application
-
LiveReload: Refreshes browser automatically
25. Spring Boot Messaging
Supports Kafka and RabbitMQ.
26. @RequestParam vs @PathVariable
| Annotation | Usage |
|---|---|
| @RequestParam | Query parameters |
| @PathVariable | URL path variables |
27. File Upload
28. Spring Boot with Thymeleaf
29. Spring Boot Starter POMs
-
spring-boot-starter-web– REST API -
spring-boot-starter-data-jpa– Database access -
spring-boot-starter-security– Security
30. Packaging Spring Boot Applications
-
JAR: Standalone executable
-
WAR: Deployable on external server
✍️ By Ashish | 2025-10-21T09:01:51.481Z