Prepare for your Spring Boot interview with these 30 essential questions covering basic, intermediate, and advanced topics. This guide is perfect for freshers, candidates with 1-3 years experience, and professionals with 3-6 years in Spring Boot development.
Basic Spring Boot Interview Questions (1-10)
1. What is Spring Boot?
Spring Boot is a framework that simplifies Spring application development by providing auto-configuration, embedded servers, and starter dependencies. It eliminates boilerplate configuration and enables rapid application development.[1][2]
2. What are the key advantages of Spring Boot?
Spring Boot offers auto-configuration, standalone applications, production-ready features through actuators, and simplified dependency management. It reduces configuration overhead and speeds up development.[2][3]
3. What is the purpose of the @SpringBootApplication annotation?
The @SpringBootApplication annotation is a convenience annotation that combines @Configuration, @EnableAutoConfiguration, and @ComponentScan. It serves as the entry point for Spring Boot applications.[2][5]
4. What are Spring Boot Starters?
Spring Boot Starters are dependency descriptors that simplify adding common framework dependencies. For example, spring-boot-starter-web includes all dependencies needed for web applications.[1][3]
5. What is Auto-Configuration in Spring Boot?
Auto-configuration automatically configures Spring beans based on classpath dependencies. It uses conditional annotations to enable configurations only when required classes are present.[2][6]
6. What is the default embedded server in Spring Boot?
Spring Boot uses Tomcat as the default embedded server. You can change it to Jetty or Undertow by excluding Tomcat and adding the desired server dependency.[1][4]
7. What is the default port for the embedded Tomcat server?
The default port for embedded Tomcat in Spring Boot is 8080. You can change it using server.port property in application.properties.[1][5]
8. How do you run a Spring Boot application?
A Spring Boot application runs using the main method with SpringApplication.run() or via Maven/Gradle plugins (mvn spring-boot:run). It starts the embedded server automatically.[4][5]
9. What is Spring Boot CLI?
Spring Boot CLI is a command-line tool for rapid prototyping. It allows running Groovy scripts without compilation and supports starter dependencies.[3][4]
10. What are the basic annotations in Spring Boot?
Key annotations include @SpringBootApplication, @RestController, @RequestMapping, @Autowired, @Service, @Repository, and @Component.[1][5]
Intermediate Spring Boot Interview Questions (11-20)
11. What is the difference between @Controller and @RestController?
@Controller is used for traditional web applications that return view names. @RestController combines @Controller and @ResponseBody, returning data directly as JSON/XML.[1][3]
12. Explain @RequestMapping vs @GetMapping
@RequestMapping is a general-purpose annotation supporting all HTTP methods. @GetMapping is a specialized version for GET requests, improving code readability.[1][3]
13. How do you handle exceptions in Spring Boot?
Use @ControllerAdvice and @ExceptionHandler annotations to create global exception handlers. This centralizes error handling across all controllers.[2][7]
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(NullPointerException.class)
public ResponseEntity<String> handleNullPointer(NullPointerException e) {
return ResponseEntity.status(500).body("Null pointer exception occurred");
}
}
14. What are Spring Profiles?
Spring Profiles allow environment-specific configurations (dev, test, prod). Activate profiles using spring.profiles.active property or spring.profiles.include.[2][7]
15. What is Spring Boot Actuator?
Spring Boot Actuator provides production-ready features like health checks, metrics, and application information through REST endpoints (/actuator/health, /actuator/metrics).[2][3]
16. How do you disable specific auto-configuration?
Use @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) or spring.autoconfigure.exclude property in application.properties.[1][5]
17. What is the role of @Autowired annotation?
@Autowired enables dependency injection by automatically wiring required beans into fields, constructors, or setter methods.[5][7]
18. How does Spring Boot handle externalized configuration?
Spring Boot supports external configuration through application.properties, application.yml, environment variables, and command-line arguments with property precedence.[2][5]
19. What is @Value annotation used for?
@Value annotation injects values from properties files, environment variables, or default values into Spring beans.[7]
@Value("${app.name:DefaultApp}")
private String appName;
20. How do you create a scenario at Paytm where you need different database configurations for different environments?
Use Spring Profiles to create application-dev.properties and application-prod.properties files. Activate the appropriate profile based on the Paytm environment using spring.profiles.active.[2][7]
Advanced Spring Boot Interview Questions (21-30)
21. Explain the internal flow of an HTTP request in Spring Boot
Request → DispatcherServlet → Controller → Service → Repository → Database → Response. Spring Boot follows MVC pattern with DispatcherServlet as the front controller.[3][4]
22. How do you implement CORS in Spring Boot?
Configure CORS globally using @CrossOrigin at controller level or WebMvcConfigurer for global configuration.[5]
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("*");
}
}
23. What is Spring Boot dependency management?
Spring Boot provides a Bill of Materials (BOM) that manages versions of common dependencies, preventing version conflicts across transitive dependencies.[1][5]
24. How would you optimize a Spring Boot application for high traffic at Zoho?
Enable Spring Boot Actuator for monitoring, use connection pooling, implement caching with @EnableCaching, and configure thread pools for async processing.[2][5]
25. What are Spring Boot Actuators endpoints useful for microservices at Salesforce?
Health checks (/actuator/health), metrics (/actuator/metrics), info (/actuator/info), and env (/actuator/env) endpoints help monitor microservices health and performance.[2][3]
26. How do you create custom health indicators in Spring Boot?
Implement HealthIndicator interface and register the bean. Spring Boot automatically exposes it via /actuator/health endpoint.[2]
@Component
public class CustomHealthIndicator implements HealthIndicator {
@Override
public Health health() {
return Health.up().withDetail("custom", "status").build();
}
}
27. Explain how to disable the embedded web server
Set spring.main.web-application-type=none in application.properties for non-web applications or exclude web starters from dependencies.[1][5]
28. In a Swiggy-like scenario, how would you handle database connection failures gracefully?
Implement @CircuitBreaker pattern using Resilience4j, custom health checks, and fallback methods in services to handle database outages.[2][5]
29. What is the purpose of spring-boot-starter-parent?
spring-boot-starter-parent provides default configurations, dependency management, and Maven plugins for Spring Boot projects.[3][5]
30. How do you register custom auto-configuration in Spring Boot?
Create a class with @Configuration and conditional annotations, then register it in META-INF/spring.factories under EnableAutoConfiguration key.[1]
Master these Spring Boot interview questions to confidently tackle technical interviews at product companies, SaaS platforms, and startups. Practice implementing these concepts in real projects for better preparation.