SPRING BOOT – 30 INTERVIEW QUESTIONS
& ANSWERS
Basic Questions
Q1. What do you understand by Spring Boot?
A: Spring Boot is an open-source Java-based framework that simplifies the development of
Spring applications by eliminating boilerplate configurations. It hides complexities of Java
web development by providing embedded servers, default configurations, and starter
dependencies.
Q2. How does Spring Boot differ from the traditional Spring Framework?
A: Traditional Spring requires manual configuration (like an unfurnished house you must
set up yourself). Spring Boot comes preconfigured with necessary tools (like a furnished
house), making it faster and easier to build applications.
Q3. What are the main features of Spring Boot?
A:
• Auto-configuration
• Spring Boot Starters
• Spring Boot Actuator
• Spring Boot Initializer
• Embedded servers (Tomcat, Jetty, Undertow)
Q4. What are Spring Boot Starters?
A: Starters are preconfigured sets of dependencies that simplify setup. Examples:
• spring-boot-starter-web
• spring-boot-starter-data-jpa
• spring-boot-starter-security
They ensure compatibility and reduce missing dependencies.
Q5. How do you create a Spring Boot application using Spring Initializer?
A: Go to start.spring.io, select project type (Maven/Gradle), language (Java), dependencies
(like Web), download the starter bundle, and import into your IDE.
Q6. What is the purpose of @SpringBootApplication annotation?
A: It is a meta-annotation that combines:
• @Configuration
• @EnableAutoConfiguration
• @ComponentScan
This reduces boilerplate and initializes the Spring context.
Q7. What is the role of application.properties file in Spring Boot?
A: It provides centralized configuration for the application (e.g., DB credentials, server
port). It lets you change behavior without altering source code.
Q8. How can you run a Spring Boot application on a custom port?
A: In application.properties, add:
server.port=8081
Q9. What is Spring Boot DevTools?
A: It’s a developer tool that enables live reload and auto-restart when code changes,
improving development speed.
Q10. What are embedded servers in Spring Boot?
A: Built-in servers like Tomcat (default), Jetty, or Undertow bundled with Spring Boot. You
don’t need to deploy separately.
Intermediate Questions
Q11. What is Spring Boot Actuator?
A: A sub-project that provides production-ready features for monitoring and managing
applications using endpoints like /actuator/health, /actuator/metrics.
Q12. How does Spring Boot Auto-Configuration work?
A: It automatically configures beans based on the dependencies present in the classpath
(using @EnableAutoConfiguration).
Q13. What is the significance of Spring Boot Starter Parent?
A: It defines default versions of dependencies, plugins, and Java versions to ensure
compatibility.
Q14. How can you define properties in Spring Boot and where are they stored?
A: Properties are stored in application.properties or application.yml. They
configure ports, DB, profiles, etc.
Q15. What is the purpose of @RestController annotation?
A: It marks a class as a RESTful controller. Return values are automatically converted to
JSON/XML for clients.
Q16. How can you create a basic REST API in Spring Boot?
A:
@RestController
public class HelloController {
@GetMapping("/")
public String home() {
return "Hello, Welcome!";
}
}
Q17. What is the difference between @Component, @Service, @Repository, and
@Controller?
A:
• @Component: Generic Spring bean.
• @Service: Business logic layer.
• @Repository: Data access layer (DAO).
• @Controller: Handles web requests.
Q18. How does Spring Boot handle dependency management?
A: It uses the starter parent POM and dependency management section in Maven/Gradle
to manage compatible versions.
Q19. What is the role of @Value annotation?
A: It injects values from application.properties into variables. Example:
@Value("${person.name}")
private String personName;
Q20. How can you implement Exception Handling in Spring Boot?
A: Use @ControllerAdvice + @ExceptionHandler to create global exception handlers
returning custom error responses.
Advanced Questions
Q21. What is the purpose of @Configuration annotation?
A: Declares a class as a source of bean definitions (blueprint for creating beans).
Q22. How does Spring Boot support Externalized Configuration?
A: It allows specifying properties outside code (e.g., environment variables, YAML, Config
Server).
Q23. What are the different ways to package a Spring Boot application?
A:
• Executable JAR
• Executable WAR
• Docker Image
• Native Image
Q24. How can you secure a Spring Boot application?
A:
• Authentication & Authorization (Spring Security)
• HTTPS
• Password encryption (BCrypt)
• JWT for session management
Q25. What is the role of @EnableAutoConfiguration annotation?
A: It tells Spring Boot to automatically configure beans based on classpath dependencies.
Q26. How can you create a RESTful Web Service using Spring Boot?
A: By creating a @RestController class with @GetMapping, @PostMapping, etc., and
exposing endpoints (e.g., /books).
Q27. What is the significance of @Entity annotation?
A: It maps a Java class to a database table, enabling ORM with JPA/Hibernate.
Q28. What are some common testing annotations in Spring Boot?
A:
• @SpringBootTest – Integration testing
• @Test – Unit testing
• @Autowired – Inject dependencies
• @MockBean – Mock dependencies
• @DataJpaTest – Repository testing
Q29. What is the purpose of application.yml file?
A: Alternative to application.properties with better readability, hierarchical structure,
and profile support.
Q30. How can you monitor and manage a Spring Boot application in production?
A: Using:
• Spring Boot Actuator
• Monitoring tools like Prometheus, Grafana
• Logging and health check endpoints